I need in urllib2. How can I install it?
I need in urllib2. How can I install it?
It looks like your web app is using Python 3.4, which doesn't use urllib2
-- the functionality that was in that module has been moved into the urllib
module. See this Stack Overflow post for more information.
I am using python 3.7, however urllib still does not work
Traceback (most recent call last): File "my.py", line 1, in <module> import urllib.request ImportError: No module named request
It's a very simple program
import urllib.request
response = urllib.urlopen("http://www.google.com") html = response.read() print(html)
Can you please install urllib? I also need to access https such as https://www.bloomberg.com, is https connection fine?
urllib
is build into Python, you don't need to install it. If you can't import request
from urllib
, it's likely that you're not using the version of Python that you think you are. How are you running the code?
BTW free accounts can only access official public APIs that are listed on our whitelist -- www.bloomberg.com
is not there because as far as we're aware, it's not an official API. If there is an official API there that you would like to access, send us a link to the API documentation and we'll add it to the whitelist.
So sounds like I am using 2.7.12. Anyway I need to install/upgrade to 3.7? Note I am a free account at this time.
00:52 ~ $ python --version Python 2.7.12
I will consider upgrade if your website provides functionalities that I am looking for.
Did you try python3.7?
ok that works! thanks a lot for the help!
Glad we could help :-)
Thanks for the help. Just upgraded the account. Will give it a try.
Excellent -- let us know how you get on :-)
Just upgraded to pay account, but still cannot access external website such as https://markets.businessinsider.com/premarket. Does it have to be white listed? Or my setting is wrong
my.py
import urllib.request fp = urllib.request.urlopen("https://markets.businessinsider.com/premarket") mybytes = fp.read() mystr = mybytes.decode("utf8") fp.close() print(mystr)
error:
Traceback (most recent call last):
File "my.py", line 3, in <module>
fp = urllib.request.urlopen("https://markets.businessinsider.com/premarket")
File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/usr/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error Tunnel connection failed: 403 Forbidden>
Are you running the code in a console that you opened before you upgraded? Old consoles will still have the old settings. If you're running the code from the editor, the easiest way to make sure you have a new console is to type exit()
into the one that is there, then click the run button again.