код работает на моем компьютере, но не работает на сервере - PullRequest
0 голосов

Я пытаюсь научиться разбираться, код работает на моем компьютере, но на сервере появляется следующая ошибка:

`Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
    conn.connect()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
    self._tunnel()
  File "/usr/lib/python3.8/http/client.py", line 898, in _tunnel
    raise OSError("Tunnel connection failed: %d %s" % (code,
OSError: Tunnel connection failed: 403 Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='evilinsult.com', port=443): Max retries exceeded with url: /generate_insult.php?lang=ru&type=text (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

Удалена половина ошибки, потому что она была слишком длинной

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/minieventbot/.local/lib/python3.7/site-packages/minieventbot.py", line 9, in <module>
    pages.append(requests.get('https://evilinsult.com/generate_insult.php?lang=ru&type=text'))
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='evilinsult.com', port=443): Max retries exceeded with url: /generate_insult.php?lang=ru&
type=text (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))`

код:

from bs4 import BeautifulSoup as BS
import requests
pages = []
pages.append(requests.get('https://evilinsult.com/generate_insult.php?lang=ru&type=text'))
for r in pages:
    html=BS(r.content,'html.parser')
    print(html)

Как исправить? Я только начинаю разбираться в парсинге, поэтому возможна глупая ошибка

...