English 中文(简体)
收到401起与Python urllib2.url open打电话不一致的错误
原标题:receiving 401 errors inconsistently from python urllib2.urlopen call

我有一幅长篇的文字,用尿布2进行了一系列的呼声。 The url is on http, but requires accreditation. 目前,我正试图管理这本书,这样它将发出100多次电话。 每当我管理该书时,有些电话都出现错误,编号为401,有些通过。 所有电话都使用相同的用户名称和密码。 (每当我手写时,这并不是同一个呼吁失败,有时是第一场呼吁失败,有时是失败的。)

为什么可能出现401人的想法不一致?

The error message printed to the screen is...

这里是用来发出呼声的方法:

def simpleExecuteRequest(minX, minY, maxX, maxY, type) :
    url =  http://myhost.com/geowebcache/rest/seed/mylayer.xml 

    msgTemplate = """<?xml version="1.0" encoding="UTF-8"?>
    <seedRequest>
    <name>mylayer</name>
    <bounds>
    <coords>
    <double>%s</double>
    <double>%s</double>
    <double>%s</double>
    <double>%s</double>
    </coords>
    </bounds>
    <gridSetId>nyc</gridSetId>
    <zoomStart>0</zoomStart>
    <zoomStop>10</zoomStop>
    <format>image/png</format>
    <type>%s</type>
    <threadCount>1</threadCount>
    </seedRequest>
    """

    message = msgTemplate%(minX, minY, maxX, maxY, type)
    headers = {  User-Agent  : "Python script",  Content-type  :  text/xml; charset="UTF-8" ,  Content-length :  %d  % len(message) }
    passwordManager = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passwordManager.add_password(None, url,  username ,  xxx )
    authenticationHandler = urllib2.HTTPBasicAuthHandler(passwordManager)
    proxyHandler = urllib2.ProxyHandler({})
    opener = urllib2.build_opener(proxyHandler, authenticationHandler)
    urllib2.install_opener(opener)    

    try :
        request = urllib2.Request(url, message, headers)
        response = urllib2.urlopen(request)
        content = response.read()
        print  success 
    except IOError, e:
        print e

有时,产出将照此办理......

<urlopen error (10053,  Software caused connection abort )>
success
success
<urlopen error (10053,  Software caused connection abort )>
<urlopen error (10053,  Software caused connection abort )>
...

在1分钟后,委员会不妨照此办理。

success
<urlopen error (10053,  Software caused connection abort )>
success
success
<urlopen error (10053,  Software caused connection abort )>

On both runs the same series of inputs for min/max x/y and type were provided in the same order. ...

最佳回答

守则对我来说是正确的,因此我看不到这个问题。

下面是关于如何开展工作的一些想法:

  • 我通常使用<代码>curl<>/code”在指挥线上填写http://quests,然后将其翻译成文字。

  • The requests library is easier to use than urllib2

  • 当你收到答复时,将标题印成正文,以便你能够看到正在发生什么。

  • Instead of except IOError, e use except IOError as e. The new way protects you from hard to find errors.

  • 我假定你照搬了用户名称和密码,并且正在使用你自己的文字中的真实文字。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签