半度逝水 2017-04-14 06:46 采纳率: 50%
浏览 6920
已采纳

python无法访问https出现URLError

URLError: "urlopen error [Errno 8] ssl.c:503: EOF occurred in violation of protocol"
直接通过浏览器可以访问,昨天也是好使的,今天就不行了
代码:
url="https://ipaddress/xxx/xxx/xxx"
kw={'xxx':'xxx'}
data = urllib.urlencode(kw)
req = urllib2.Request(url,data)
base64string = base64.encodestring('%s:%s' % ('xxx', 'xxx'))[:-1] #这里最后会自动添加一个\n
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
return_data = urllib2.urlopen(req) #请求url
data = return_data.read() #读取内容
print data
错误:
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
debugger.run(codeObject, __main
_.__dict__, start_stepping=0)
File "C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger__init__.py", line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python27\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 655, in run
exec cmd in globals, locals
File "C:\Users\wzs\Desktop\get_resulte.py", line 2, in
import urllib
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 394, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 412, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1207, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "C:\Python27\lib\urllib2.py", line 1174, in do_open
raise URLError(err)
URLError:

  • 写回答

1条回答

  • threenewbee 2017-04-15 02:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿