Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: #12

Open
seraph776 opened this issue Oct 11, 2022 · 1 comment
Open

UnboundLocalError: #12

seraph776 opened this issue Oct 11, 2022 · 1 comment

Comments

@seraph776
Copy link

I am using pipenv virtual environment on Windows 11 OS . I took the following steps to receive the error.

  1. Installed nvironment shadow-useragent:
  1. Ran the following the example script specified in the Usage documentation:
import shadow_useragent 
ua = shadow_useragent.ShadowUserAgent()

# Access user-agent per Percentage of Use
ua = ua.percent(0.03) 
ua = ua.most_common

I received the following Traceback messages:

Traceback (most recent call last):
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='51.158.74.109', port=443): Max retries exceeded with url: /useragents/?format=json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 35, in _update
    r = requests.get(url=self.URL)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\sessions.py", line 723, in send
    history = [resp for resp in gen]
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\sessions.py", line 723, in <listcomp>
    history = [resp for resp in gen]
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\sessions.py", line 266, in resolve_redirects
    resp = self.send(
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='51.158.74.109', port=443): Max retries exceeded with url: /useragents/?format=json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Seraph776\Desktop\WebScraping\projects\quotes-to-scrape.com\script\script.py", line 38, in <module>
    ua = ua.percent(0.03)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 112, in percent
    return self.get_useragent(percent=percent)
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 96, in get_useragent
    uas = self.get_uas()
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 73, in get_uas
    self.update()
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 59, in update
    self._update()
  File "C:\Users\Seraph776\.virtualenvs\quotes-to-scrape.com-IeVSPFIO\lib\site-packages\shadow_useragent\core.py", line 38, in _update
    self.logger.error(r.content.decode('utf-8'))
UnboundLocalError: local variable 'r' referenced before assignment

Any help would be greatly appreciated!

@MrDebugger
Copy link

@seraph776 that's because, the module used '51.158.74.109' host to update and retrieve user agents which is now not in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants