urllib2.HTTPError:HTTP 错误 410:消失了

问题描述 投票:0回答:3

我用 python 编写了以下程序,用于在 python 中搜索推文:

#Importing the modules
import urllib2
import json

screen_name = "wordpress"

url = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=" + screen_name

data = json.load(urllib2.urlopen(url))

print len(data), "tweets"

for tweet in data:
    print tweet['text']

但是我遇到了以下错误。我对 Python 比较陌生。

File "twitter.py", line 9, in <module>
    data = json.load(urllib2.urlopen(url))
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 410: Gone

请帮忙。

python python-2.7 twitter
3个回答
0
投票

410错误意味着资源不再可用。这与“从未存在过”不同。这意味着该 url 在服务器上不再可用,或者已更改名称。我怀疑twitter api已经改变了。

了解更多信息:410错误


0
投票

我在 pytube 模块中遇到了同样的问题,并按如下方式安装了它

python -m pip install git+https://github.com/Zeecka/pytube@fix_1060


-1
投票

在遵循 pytube 教程(标题为“YouTube 视频下载器 | Python 项目 | Pytube | 简单教程”)时遇到相同的错误。 通过在 Windows 命令提示符中使用以下命令更新 pytube 来修复此问题:

python -m pip install --upgrade pytube

希望能解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.