Use of python urllib

urllib library request Send request urlopen Definition: urllib . request . urlopen(url, data=None, [timeout ]*, cafile=None, capath=None, cadefault=False, context=None) When there is no data parameter, request data according to the get method import urllib.request response = urllib.request.urlopen(‘https://www.python.org’) print(response. read(). decode(‘utf-8’)) # output page html source code print(type(response)) # <class ‘http.client.HTTPResponse’> print(response. status) print(response. getheaders()) print(response. […]

Python error: ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+

Article directory Python error: ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1 + 1. Problem description 2. Problem analysis 3. Solutions After upgrading openssl, still import urllib3 error Idea 1: Recompile python Idea 2: Specify the Python interpreter to link to the new version of OpenSSL without recompiling Python 4. The relationship between python compilation and […]

Python’s various network request libraries urllib3 requests aiohttp request http and https efficiency comparison, multi-threading, gevent, asyncio comparison, super large thread pool, 2n + 1 thread pool comparison…

The three purposes of this article are not to go astray by just obsessing with concepts. Some people think that there is a set of concepts, but in fact it is not what they think. This article uses various network request libraries, various concurrency modes, and thread pools of various sizes to test 50,000 requests […]

[Solved] Resolve pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool

Solve pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=’files.pythonhosted.org’, port=443): Read timed out problem Install torch with the command: pip3 install torch==1.10.0 + cu113 torchvision==0.11.1 + cu113 torchaudio===0.10.0 + cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html – i http://mirrors.aliyun.com/pypi/simple/ –trusted-host mirrors.aliyun.com At this time, the error is reported: pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=’download.pytorch.org’, port=443): Read timed out. 2. Analyze the cause of the problem (1) There is a […]

[Solved] Python3 urllib request webpage error (AttributeError: module ‘urllib’ has no attribute ‘request’)

error code python3.8, I want to use the urllib library to request access to the post bar, the error code is as follows: def load_page(url, filename): headers = {“User-Agent”:”Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0;)”} request = urllib.request.Request(url,headers=headers) return urllib.request.urlopen(request).read() Error message: see two requests light up, indicating that there is a problem error after running Error content […]

[Solved] [Python3] Crawler HTTP Error 500 error, error message: urllib.error.HTTPError: HTTP Error 500: INTERNAL SERVER ERROR

Error code # @author tianyi #{Time}-2022-09-11 08:40 import urllib.parse import urllib.request def create_request(page): base_url = ‘https://movie.douban.com/j/chart/top_list?type=7 &interval_id=100:90 &action= &start=0 &limit=20’ data = {<!– –> ‘start’ :(page-1)*20, ‘limit’: 20 } print(data) print(‘———————————————‘) data = urllib.parse.urlencode(data) url = base_url + data print(url) header = {<!– –> ‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) […]

[Solved] [Pytorch] Download CIFAR10 dataset error: urllib.error.URLError: <urlopen error name: https) Effective solution

[Pytorch] Download CIFAR10 dataset error: urllib.error.URLError: First To add the following two lines of code before the code starts (mine is windows 10 system) import ssl ssl._create_default_https_context = ssl._create_unverified_context But You will find that this error will be reported when you run the code next: import _ssl # if we can’t import it, let the […]

[Solved] urllib.error.URLError prompt error solution and basic knowledge of crawler

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)> Add: in the first line of the code: it can be solved import ssl ssl._create_default_https_context = ssl._create_unverified_context The code is as follows: import urllib import urllib.request import ssl ssl._create_default_https_context = ssl._create_unverified_context data1 = bytes(urllib.parse.urlencode({‘name’: ‘geometry’}), encoding=’utf-8′) response = urllib.request.urlopen(‘https://www.httpbin.org/post’, data=data1) […]

[Solved] ModuleNotFoundError: No module named ‘urllib.parse’; ‘urllib’ is not a package [solution]

import urllib.parse kw = {‘wd’:’Piggy’} result = urllib.parse.urlencode(kw) print(result) When learning urllib, the simple code above appeared when running ModuleNotFoundError: No module named ‘urllib.parse’; ‘urllib’ is not a package This error, and then I went to Baidu to find out that urllib is a library that comes with python. I also went to download it […]