Python uses IP proxy examples and error resolution methods

Source: Internet
Author: User


One, code example

#-*-Coding:utf-8-*-import requestsheader = {' user-agent ': ' mozilla/5.0 (Windows NT 6.1; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/53.0.2785.143 safari/537.36 '}proxy_ip = {' https ': ' https://115.28.1 48.137:8118 '}html = Requests.get ("http://www.baidu.com", Headers=header, proxies=proxy_ip) print Htmlprint Html.text

Second, by modifying the proxy IP server address of the PROXY_IP parameter, you can change the proxy IP


Third, error notification

Requests.exceptions.ProxyError:HTTPSConnectionPool (host= ' www.baidu.com ', port=443): Max retries exceeded with URL:/( Caused by Proxyerror (' Cannot connect to proxy ', error (10054, ')))


There are generally 2 reasons for the error:

1. IP Proxy Server is not working properly

2, IP proxy use of the protocol is not normal, such as HTTP//and https://can not be written wrong


If it is an HTTP proxy, then write as follows:

proxy_ip = {' http ': ' http://115.28.148.137:8118 '}

If it is an HTTPS proxy server, the following is the wording:

Proxy_ip = {' https ': ' https://115.28.148.137:8118 '}


Python uses IP proxy examples and error resolution methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.