gpt4 book ai didi

python urllib2.urlopen SSL : CERTIFICATE_VERIFY_FAILED

转载 作者:行者123 更新时间:2023-12-01 09:08:29 25 4
gpt4 key购买 nike

我的运行环境是:Python2.7、django1.9

我原来的代码是:

req = urllib2.Request(url, obj, headers)
opener = urllib2.urlopen(req)

但是出现错误:[SSL: CERTIFICATE_VERIFY_FAILED],我在网上找到了解决方案:

First:
import ssl
import urllib2

context = ssl._create_unverified_context()
print urllib2.urlopen("https://imaojia.com/", context=context).read()

Second:
import ssl
import urllib2

ssl._create_default_https_context = ssl._create_unverified_context
print urllib2.urlopen("https://imaojia.com/").read()

我使用它们后,现在代码变成:

req = urllib2.Request(url, obj, headers)
import ssl
opener = urllib2.urlopen(req, context=ssl._create_unverified_context())

现在有新错误:

HTTP Error 503: Service Unavailable

Internal Server Error: /deploy/key_list_import/
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/project/soms/deploy/views.py", line 398, in salt_key_import
minions,minions_pre = sapi.list_all_key()
File "/project/soms/deploy/saltapi.py", line 54, in list_all_key
self.token_id()
File "/project/soms/deploy/saltapi.py", line 30, in token_id
content = self.postRequest(obj,prefix='/login')
File "/project/soms/deploy/saltapi.py", line 42, in postRequest
opener = urllib2.urlopen(req, context=ssl._create_unverified_context())
File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable

谁能给我一些建议?谢谢!

最佳答案

感谢 Chiheb Nexus 的回答帮助我解决了问题,因此关闭此问题,回答并采纳它。

这个问题的答案是我的请求会导致 HTTP 错误 503。

关于python urllib2.urlopen SSL : CERTIFICATE_VERIFY_FAILED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51854367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com