import M2Crypto import urllib print urllib.urlopen(("https://graph.facebook.com/me?" + urllib.urlencode({'access_token': [your access token here]'}).read()
...but this works:
import M2Crypto import urllib urllib._urlopener = urllib.FancyURLopener() urllib._urlopener.addheader('Connection', 'close') u = urllib.urlopen("https://graph.facebook.com/me?" + urllib.urlencode({'access_token': [your access token here]'})) data = u.read() print data
The urllib._urlopener code is essentially what is done by urllib.urlopen(). The major difference is that we add a Connection: close header.
If the Facebook SDK code would just change to use urllib2 instead of urllib2, the issue goes away (most likely because M2Crypto hasn't been hijacking the code). The urllib2 automatically adds a Connection: close header (see http://docs.python.org/library/urllib2.html)
import M2Crypto import urllib print urllib2.urlopen(("https://graph.facebook.com/me?" + urllib.urlencode({'access_token': [your access token here]'}).read()
Any idea when this behavior began? I first started seeing it today. Thanks for the tip!
ReplyDeleteI just started seeing the issue after we started to use M2Crypto (or rather importing Google's Gdata code). I haven't dug around the M2Crypto code to figure out how its behavior is different than that of standard urllib library, but it appears to keep the socket open and not return back data until the connection is closed (if you specify the # of bytes to read, then the # of bytes are returned).
ReplyDelete