[英]Python - urllib2.HTTPError 400 bad request
我正在學習如何訪問Twitter API,但是當我運行以下簡單代碼時,出現錯誤“ urllib2.HTTPError:HTTP錯誤400:錯誤的請求”:
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)
我不確定為什么-我已經在Google周圍搜索了,似乎無法找到為什么這會返回Bad Request錯誤。 謝謝你的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.