1

I have a probleem in this part of code. It opens the connection and just freezes not proceeding to f.close, so the script is not running further.

if "opened" in line:
            print "You just received some mail! Wow!"
            data = json.dumps({"url":"awesome url", "data":"awesome data"})
            req = urllib2.Request("http://1.2.3.4:8080/", data, {'Content-Type':'application/json'})
            f = urllib2.urlopen(req)
            response = f.read()
            print (response)
            f.close()             
Kate
  • 49
  • 1
  • 8
  • `f.read()` might block for a long time if there is a lot of data to be read. Try `f.read(100)` (which will read the first 100 bytes) to see if it is working at all, or the problem might be elsewhere. – skyguy126 Sep 18 '16 at 07:06
  • I tried using it without f.read() at all, and it still freezed. I am sure that it happens at the point of urlopen (I checked where it stops with prints) – Kate Sep 18 '16 at 07:12
  • Take a look at this: http://stackoverflow.com/questions/16772795/urllib2-urlopen-will-hang-forever-despite-of-timeout Make sure your IP is correct and if all else fails I would suggest using [requests](http://docs.python-requests.org/en/master/) – skyguy126 Sep 18 '16 at 17:41

0 Answers0