在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python  網(wǎng)絡(luò)安全/ python urlopen 怎么同時(shí)使用url,參數(shù),header和conte

python urlopen 怎么同時(shí)使用url,參數(shù),header和context?

問(wèn)題描述

python urlopen 怎么同時(shí)使用url,參數(shù),頭信息和context?
原來(lái)的代碼是這樣的:

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

現(xiàn)在出現(xiàn)[SSL: CERTIFICATE_VERIFY_FAILED]的報(bào)錯(cuò)

所以我需要使用下面的代碼處理報(bào)錯(cuò):

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

請(qǐng)問(wèn)怎么把這個(gè)context加入進(jìn)去?
嘗試過(guò) print urllib2.urlopen(url=req, context=context).read()
報(bào)錯(cuò):
HTTP Error 503: Service Unavailable

我使用下面的代碼,也是一樣報(bào)錯(cuò)HTTP Error 503: Service Unavailable

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

調(diào)試信息:

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
回答
編輯回答
有你在

503是request錯(cuò)誤導(dǎo)致的,檢查了request有問(wèn)題

2017年9月30日 22:42