请求代理脚本错误

时间:2021-08-19 18:10:15

I am currently working on a script that pulls info from supremenewyork.com this proxy script i was using was working "sorta" before and now it doesnt work at all ever since I saw this thing in my computer called urllib3 i thought it was useless so I uninstalled it then I tryed to run my proxy script again and I got an error that said something about urllib3 so I quickly re installed urllib3 but my script never worked again after that... Here is my script:

我目前工作在一个脚本,该脚本将信息从supremenewyork.com这个代理脚本我用“近似”工作之前和现在不工作自从我看到这个东西在我的电脑叫urllib3我认为这是无用的所以我卸载它然后我试着再次运行我的代理脚本,我得到了一个错误,说一些关于urllib3所以我很快重新安装urllib3但脚本后不会再工作了……这是我的脚本:

import requests
from bs4 import BeautifulSoup
UK_Proxy1 = input('UK http Proxy1: ')
UK_Proxy2 = input('UK http Proxy2: ')

proxies = {
 'http': 'http://' + UK_Proxy1 + '',
   'https': 'http://' + UK_Proxy2 + '',

}

categorys = ['jackets','shirts','tops_sweaters','sweatshirts','pants','shorts','t-shirts','hats','bags','accessories','shoes','skate']
catNumb = 0

for cat in categorys:
    catStr = str(categorys[catNumb])
    cUrl = 'http://www.supremenewyork.com/shop/all/' + catStr
    proxy_script = requests.get(cUrl, proxies=proxies).text
    bSoup = BeautifulSoup(proxy_script, 'lxml')
    print('\n*******************"'+ catStr.upper() + '"*******************\n')
catNumb += 1
for item in bSoup.find_all('div', class_='inner-article'):
    url = item.a['href']
    alt = item.find('img')['alt']
    req = requests.get('http://www.supremenewyork.com' + url)
    item_soup = BeautifulSoup(req.text, 'lxml')
    name = item_soup.find('h1', itemprop='name').text
    style = item_soup.find('p', itemprop='model').text
    print (alt + ' --- ' + name + ' --- ' + style)

When I run this script and I input a uk proxy I get this error

当我运行这个脚本并输入一个uk代理时,我得到了这个错误

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

在处理上述异常时,发生了另一个异常:

  Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred:

在处理上述异常时,发生了另一个异常:

`Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred: (same error as above and continues for a bit)

 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max retries exceeded with url: http://www.supremenewyork.com/shop/all/jackets (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)))

I have tried several different proxys and none have worked Can someone please help me out I would really apreciate it

我试过几种不同的代理,但没有一个人能帮我,我真的很感激。

1 个解决方案

#1


1  

Here the baseline of the answer, it doesn't work because the proxy isn't being connected to.

这里是答案的基线,它不起作用,因为代理没有被连接到。

All you have to do is provide it with a working proxy and a port, it would've given you the same error if your computer doesn't have internet connection but since you're on * I would assume that you have that.

你所要做的就是为它提供一个可用的代理和一个端口,如果你的计算机没有网络连接,它会给你同样的错误,但是由于你在*上,我假设你有那个。

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max retries exceeded with url: http://www.supremenewyork.com/shop/all/jackets (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))) Here is how we fix it: We don't we use a proxy that works and provide it with a port, you can get a list of proxies on this website and use random.choice() to always choose a different one.http://www.gatherproxy.com/

urllib3.exceptions。MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max重试超过了url: http://www.supremenewyork.com/shop/all/jacket(由ProxyError(“无法连接到代理”)。”,NewConnectionError(“< urllib3.connection。HTTPConnection对象在0 x112d10eb8 >:未能建立一个新的连接:[Errno 8]节点名和servname提供,或不知道,)))这是我们如何改正:我们不使用代理,并提供一个港口,你可以得到一个代理列表在这个网站上和使用random.choice()总是选择不同的one.http:/ /www.gatherproxy.com/

import requests
from bs4 import BeautifulSoup
UK_Proxy1 = '173.212.202.65:80'
# UK_Proxy2 = input('UK http Proxy2: ')

proxies = {
 'http': 'http://' + UK_Proxy1,
   'https': 'https://' + UK_Proxy1
}

categorys = ['jackets','shirts','tops_sweaters','sweatshirts','pants','shorts','t-shirts','hats','bags','accessories','shoes','skate']
catNumb = 0

for cat in categorys:
    catStr = str(categorys[catNumb])
    cUrl = 'http://www.supremenewyork.com/shop/all/' + catStr
    proxy_script = requests.get(cUrl, proxies=proxies).text
    bSoup = BeautifulSoup(proxy_script, 'lxml')
    print('\n*******************"'+ catStr.upper() + '"*******************\n')
catNumb += 1
for item in bSoup.find_all('div', class_='inner-article'):
    url = item.a['href']
    alt = item.find('img')['alt']
    req = requests.get('http://www.supremenewyork.com' + url)
    item_soup = BeautifulSoup(req.text, 'lxml')
    name = item_soup.find('h1', itemprop='name').text
    style = item_soup.find('p', itemprop='model').text
    print (alt + ' --- ' + name + ' --- ' + style)

#1


1  

Here the baseline of the answer, it doesn't work because the proxy isn't being connected to.

这里是答案的基线,它不起作用,因为代理没有被连接到。

All you have to do is provide it with a working proxy and a port, it would've given you the same error if your computer doesn't have internet connection but since you're on * I would assume that you have that.

你所要做的就是为它提供一个可用的代理和一个端口,如果你的计算机没有网络连接,它会给你同样的错误,但是由于你在*上,我假设你有那个。

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max retries exceeded with url: http://www.supremenewyork.com/shop/all/jackets (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))) Here is how we fix it: We don't we use a proxy that works and provide it with a port, you can get a list of proxies on this website and use random.choice() to always choose a different one.http://www.gatherproxy.com/

urllib3.exceptions。MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max重试超过了url: http://www.supremenewyork.com/shop/all/jacket(由ProxyError(“无法连接到代理”)。”,NewConnectionError(“< urllib3.connection。HTTPConnection对象在0 x112d10eb8 >:未能建立一个新的连接:[Errno 8]节点名和servname提供,或不知道,)))这是我们如何改正:我们不使用代理,并提供一个港口,你可以得到一个代理列表在这个网站上和使用random.choice()总是选择不同的one.http:/ /www.gatherproxy.com/

import requests
from bs4 import BeautifulSoup
UK_Proxy1 = '173.212.202.65:80'
# UK_Proxy2 = input('UK http Proxy2: ')

proxies = {
 'http': 'http://' + UK_Proxy1,
   'https': 'https://' + UK_Proxy1
}

categorys = ['jackets','shirts','tops_sweaters','sweatshirts','pants','shorts','t-shirts','hats','bags','accessories','shoes','skate']
catNumb = 0

for cat in categorys:
    catStr = str(categorys[catNumb])
    cUrl = 'http://www.supremenewyork.com/shop/all/' + catStr
    proxy_script = requests.get(cUrl, proxies=proxies).text
    bSoup = BeautifulSoup(proxy_script, 'lxml')
    print('\n*******************"'+ catStr.upper() + '"*******************\n')
catNumb += 1
for item in bSoup.find_all('div', class_='inner-article'):
    url = item.a['href']
    alt = item.find('img')['alt']
    req = requests.get('http://www.supremenewyork.com' + url)
    item_soup = BeautifulSoup(req.text, 'lxml')
    name = item_soup.find('h1', itemprop='name').text
    style = item_soup.find('p', itemprop='model').text
    print (alt + ' --- ' + name + ' --- ' + style)