0
 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')>
Jonah
  • 2,097
  • 4
  • 20
  • 22
  • "Connection reset by peer" is a hint. Your peer (the server) reset the connection. – S.Lott Sep 19 '11 at 18:49
  • So does this mean the server Im uploading the file to is rejecting my request? – Jonah Sep 19 '11 at 18:52
  • "rejecting"? Hard to say. It's dropping the connection. Who knows why? You have to read the content of the "request" object to get the status code, headers and body. Then you can **update** your question to remove the (almost) useless stack trace and include really interesting facts about the response you're getting. – S.Lott Sep 19 '11 at 19:11
  • The problem is I am not getting any response. I tried to print it in the next line `print(urllib2.urlopen(request).read())` but it does'nt show anything just throws the above error. – Jonah Sep 19 '11 at 19:23
  • A reply has a header, which may be something you can print. Please **update** the question with this, if it's available. If you can't display the header, then, your server has simply cut you off without much warning. – S.Lott Sep 19 '11 at 19:33

1 Answers1

2

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.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
  • Yeah I had a choppy connection that day so the server was not responding properly its working now..anyways thanks for the effort!!! – Jonah Sep 21 '11 at 17:26