Python - urllib2.HTTPError 400 错误请求
我正在学习如何访问Twitter的API,但在运行下面这段简单代码时,出现了“urllib2.HTTPError: HTTP Error 400: Bad Request”的错误:
import urllib2
import simplejson
url = "https://api.twitter.com/1.1/search/tweets.json?screen_name=twitterapi"
if __name__ == "__main__":
req = urllib2.Request(url)
opener = urllib2.build_opener()
f = opener.open(req)
json = simplejson.load(f)
for item in json:
print item.get("created_at") # this will get the section that is "Created At from JSON"
print item.get('text') # this will get the text (in Twitter, a Tweet)
我不太明白为什么会这样——我在网上查了很多资料,但还是找不到导致这个错误的原因。谢谢大家的帮助!