【问题标题】:Unable to fetch url in python无法在python中获取url
【发布时间】:2019-06-30 18:16:11
【问题描述】:

我无法从 biblegateway.com 获取 url,它显示错误为 urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure> 请不要重复,因为我浏览了重复显示的站点,我访问该站点时无法理解。

这是我的代码

import urllib2
url = 'https://www.biblegateway.com/passage/?search=Deuteronomy+1&version=NIV'
response = urllib2.urlopen(url)
html = response.read()
print html

【问题讨论】:

标签: python python-2.7 urllib2


【解决方案1】:

这是fetching url 的一个很好的参考。

在 python 3 中你可以:

from urllib.request import urlopen
URL = 'https://www.biblegateway.com/passage/?search=Deuteronomy+1&version=NIV'
f = urlopen(URL)
myfile = f.read()
print(myfile)

但不确定它是否能解决 SSL 问题。或许有一些线索here

【讨论】:

  • 它显示AttributeError: 'module' object has no attribute 'request' @Evgeny
  • 在 python 3 中运行它吗?
  • 它现在可以通过将import urllib替换为import urllib.request@Evgeny来工作
  • 对,在 3.6 中确实如此。它会绕过 ssl 错误吗?
  • 另外,requestsurllib 更容易,更高级
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2019-11-27
  • 2021-05-09
  • 1970-01-01
相关资源
最近更新 更多