urlopen错误[Errno 54]连接由同行重置

时间:2018-06-15 09:01:27

标签: django macos python-2.7 openssl urllib2

异常位置:/ library / Frame /Python.framework / Version / 2.7 / lib / python2.7 / urllib2.py在do_open,第1198行

  • Mac OS X,
  • Django版本:1.8.19,
  • Python版本:2.7.13,
  • 请求方法:GET,
  • OpenSSL 0.9.8zh 2016年1月14日

嗨,有人解决了这个问题吗? pip install pyopenssl ndg-httpsclient pyasn1pip install requests[security]对我没有帮助,如果您需要更多信息,我会怀疑它。

回溯:

File "/Users/ernekyan/project/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/ernekyan/project/venv/lib/python2.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "/Users/ernekyan/project/kernel/views.py" in dispatch
  34.         return super(AjaxViewMixin, self).dispatch(request, *args, **kwargs)
File "/Users/ernekyan/project/venv/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  89.         return handler(request, *args, **kwargs)
File "/Users/ernekyan/project/venv/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  268.         return super(BaseUpdateView, self).get(request, *args, **kwargs)
File "/Users/ernekyan/project/venv/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  206.         return self.render_to_response(self.get_context_data(form=form))
File "/Users/ernekyan/project/shop/views.py" in get_context_data
  283.                 self.object.full_price))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in urlopen
  154.     return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in open
  429.         response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in _open
  447.                                   '_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in _call_chain
  407.             result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in https_open
  1241.                 context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py" in do_open
  1198.             raise URLError(err)

Exception Type: URLError at /cart/checkout/payment
Exception Value: <urlopen error [Errno 54] Connection reset by peer>

views.py

def get_context_data(self, **kwargs):
    context = super(CartPaymentInfo, self).get_context_data(**kwargs)
    vOutPrice = self.object.full_price
    import urllib2
    import xml.etree.ElementTree
    response = urllib2.urlopen(
        'https://auth.robokassa.ru/Merchant/WebService/Service.asmx/CalcOutSumm?MerchantLogin=project&IncCurrLabel=QCardR&IncSum={}'.format(
            self.object.full_price))
    result = response.read()
    root = xml.etree.ElementTree.fromstring(result)
    for child in root:
        if child.tag.endswith('OutSum'):
            vOutPrice = float(child.text)

0 个答案:

没有答案