How is 618 sales champion made?Uncover the secret of e-commerce’s “invigorating” hundreds of millions of sales data>>>
I want to learn how to set up proxy server for crawler urllib, so I picked up urllib that I didn’t learn before and typed a simple code as follows
import urllib.request
url = "http://www.baidu.com"
data = urllib.request.urlopen(url).read()
data = data.decode('UTF-8')
print(data)
However, errors are always reported after execution
Traceback (most recent call last):
File "urllib.py", line 1, in <module>
import urllib.request
File "F:\python\urllib.py", line 1, in <module>
import urllib.request
ImportError: No module named 'urllib.request'; 'urllib' is not a package
I’ve tried to use fromurl lib import request, PIP install urllib
Or the same problem. After saving py file, you will be prompted to import rror:Nomodulenamedrequest 。
But it works in Python shell
Many search, found that is too silly x error
It turned out to be my file naming problem
The priority of system search module is: program main directory, then the path defined by system environment variables, and then the standard library directory. If we find it in this order, we will not look down. Because the file name is exactly urllib, I intended to import urllib under the directory of the standard library. As a result, I imported my current file
Reflection:
I found it in stack overflow at the beginning, but when I saw that the background of the problem was version 2.7, I didn’t continue to look down. I firmly believed that the application method of urllib was wrong, and that there was no reference value if it wasn’t version 3.6
There are some differences between python2.7 and 3. X code, but the reason for the error may be the same
Similar Posts:
- ModuleNotFoundError No module named urllib2
- The solution of module ‘urllib’ has no attribute ‘request’
- Python crawling picture prompt urllib.error.httperror: http error 403: forbidden solution
- Differences of urllib, urllib2, httplib and httplib2 libraries in Python
- Python: Centos + gunicorn+flask ImportError: No module named request
- Pycharm cannot import the third-party library no module named urllib3
- How to Solve Python Error: “HTTP Error 403: Forbidden”
- Python3 Use urlliburlopen error EOF occurred in violation of protocol (_ssl.c:841)
- [Solved] Python3.7 Install urllib.parse[UNK]json[UNK]re
- Interface automation (8): an error is reported during interface testing sslerror: Certificate verify failed