Python: appengine urllib2 headers from a 302
A normal urllib2
works fine:
>>> import urllib2
>>> r = urllib2.urlopen(u"http://bit.ly/4ovTZw")
>>> r.geturl()
'http://www.writing.com/main/handler/action/show_document/item_id/933413.mp3'
>>> r.headers.get("Content-Type")
'audio/mpeg'
But in appengine, the same code shows text/html
.
def get(self):
r = urllib2.urlopen(u"http://bit.ly/4ovTZw")
self.response.out.write( r.geturl() )
se开发者_如何学运维lf.response.out.write( r.headers.get("Content-Type") )
return
Can I get around this? Why is this happening?
I have just tried to call that specifi url via Interactive Shell; it works for me using the urlfetch function.
Google App Engine/1.4.2
Python 2.5.2 (r252:60911, May 12 2010, 14:18:27)
[GCC 4.3.1]
>>> from google.appengine.api import urlfetch
>>> result = urlfetch.fetch('http://bit.ly/4ovTZw')
>>> print result.headers['content-type']
audio/mpeg
I know for a fact that AppEngine blacklists some addresses - check your response body for a hint.
It might also be the other way around - some services blacklist AppEngine... I am not sure. I remember in the early days of GAE, accessing Delicious was not possible through AppEngine.
精彩评论