Search code examples
pythonposter

Program abruptly stops and throws URLERROR


 from poster.encode import multipart_encode
 from poster.streaminghttp import register_openers

    def picscrazy(str,int):


          register_openers()
          datagen, headers = multipart_encode({"imagefile[]": open(str, "rb")})
          request = urllib2.Request("http://www.picscrazy.com/process.php", datagen, headers)

Str is the filename and the int is just another flag. The code is to upload a file to a image hosting website .I am using poster Poster for the post requests. The program stops after the request statement and gives an error .I cant understand the error whether its a problem in my network or in the program. Below is the traceback of the error:

 Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\Desktop\for exbii\res.py", line 42, in <module>
    picscrazy(fname,1)
  File "C:\Documents and Settings\Administrator\Desktop\for exbii\res.py", line 14, in picscrazy
    print(urllib2.urlopen(request).read())
  File "C:\Python25\Lib\urllib2.py", line 121, in urlopen
    return _opener.open(url, data)
  File "C:\Python25\Lib\urllib2.py", line 374, in open
    response = self._open(req, data)
  File "C:\Python25\Lib\urllib2.py", line 392, in _open
    '_open', req)
  File "C:\Python25\Lib\urllib2.py", line 353, in _call_chain
    result = func(*args)
  File "C:\Python25\lib\poster\streaminghttp.py", line 142, in http_open
    return self.do_open(StreamingHTTPConnection, req)
  File "C:\Python25\Lib\urllib2.py", line 1076, in do_open
    raise URLError(err)
URLError: <urlopen error (10054, 'Connection reset by peer')>

Solution

  • If you can't display the header coming back from the server, then, your server has simply cut you off.

    It may be your request is bad -- but that's unlikely.

    It may be that you've exceeded bandwidth restrictions.

    It may be that your requests appear to be a DDOS attack because they're happening too frequently.