torpyorg / torpy

Pure python Tor client implementation
Apache License 2.0
411 stars 53 forks source link

urllib.error.HTTPError when using the example code #10

Closed Ahthe45th closed 4 years ago

Ahthe45th commented 4 years ago

I have been trying to use the tor_requests_session for quite sometime but i keep getting the same error. In my latest attempt i tried to use example code from this repo as follows

def test_requests_session():
    tor = TorClient()
    with tor.get_guard() as guard:
        adapter = TorHttpAdapter(guard, 3)

        with requests.Session() as s:
            s.headers.update({'User-Agent': 'Mozilla/5.0'})
            s.mount('http://', adapter)
            s.mount('https://', adapter)

            r = s.get('https://google.com', timeout=30)
            logger.warning(r)
            logger.warning(r.text)
            assert r.text.rstrip().endswith('</html>')

            r = s.get('https://stackoverflow.com/questions/tagged/python')
            assert r.text.rstrip().endswith('</html>')
            logger.warning(r)
            logger.warning(r.text)

But i get the following traceback:

Traceback (most recent call last):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 175, in renew
    if not self.verify(new_doc):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 200, in verify
    pubkey = self._get_pubkey(sign['identity'], sign['signing_key_digest'])
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 207, in _get_pubkey
    key_certificate = provider.download_fp_sk(identity, signing_key_digest)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 80, in download_fp_sk
    return http_get('{}/{}-{}'.format(self.fp_sk_url, identity, keyid))
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 190, in http_get
    with opener.open(url, timeout=timeout) as response:
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Directory busy, try again later
WARNING:torpy.utils:Retry with another authority...
ERROR:root:[ignored]
Traceback (most recent call last):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 175, in renew
    if not self.verify(new_doc):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 200, in verify
    pubkey = self._get_pubkey(sign['identity'], sign['signing_key_digest'])
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 207, in _get_pubkey
    key_certificate = provider.download_fp_sk(identity, signing_key_digest)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 80, in download_fp_sk
    return http_get('{}/{}-{}'.format(self.fp_sk_url, identity, keyid))
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 190, in http_get
    with opener.open(url, timeout=timeout) as response:
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Directory busy, try again later
WARNING:torpy.utils:Retry with another authority...
ERROR:root:[ignored]
Traceback (most recent call last):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 175, in renew
    if not self.verify(new_doc):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 200, in verify
    pubkey = self._get_pubkey(sign['identity'], sign['signing_key_digest'])
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 207, in _get_pubkey
    key_certificate = provider.download_fp_sk(identity, signing_key_digest)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 80, in download_fp_sk
    return http_get('{}/{}-{}'.format(self.fp_sk_url, identity, keyid))
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 190, in http_get
    with opener.open(url, timeout=timeout) as response:
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Directory busy, try again later
WARNING:torpy.utils:Retry with another authority...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/yaqub/conscious/configs/endpoints/utils.py", line 35, in test_requests_session
    tor = TorClient()
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/client.py", line 37, in __init__
    self._consensus = consensus or TorConsensus()
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 145, in __init__
    self.renew()
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 78, in newfn
    return func(*args, **kwargs)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 175, in renew
    if not self.verify(new_doc):
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 200, in verify
    pubkey = self._get_pubkey(sign['identity'], sign['signing_key_digest'])
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 207, in _get_pubkey
    key_certificate = provider.download_fp_sk(identity, signing_key_digest)
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/consesus.py", line 80, in download_fp_sk
    return http_get('{}/{}-{}'.format(self.fp_sk_url, identity, keyid))
  File "/home/ibnudawud/Projects/Programming/project_yaqub_as/projectenv/lib/python3.8/site-packages/torpy/utils.py", line 190, in http_get
    with opener.open(url, timeout=timeout) as response:
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Directory busy, try again later

Why does this happen?

jbrown299 commented 4 years ago

duplicate #8