Xabier Mikel
Xabier Mikel

Reputation: 21

Urllib2 Not installed?

I coded this:

from datetime import datetime, timedelta

import json
import time
import urllib2

...

req=urllib2.Request(api_url,binary_data,header)

f=urllib2.urlopen(req)

My python version is the 3.6.5 so i´m supposed to have the urllib2 installed already but every time i get this error:

import urllib2 
ModuleNotFoundError: no module named 'URLLIB2'

I changed the name to urllib3 as it appears in my anaconda folder but it crashes anyway.... what do i do?

Upvotes: 1

Views: 4759

Answers (1)

Xantium
Xantium

Reputation: 11605

Urllib2 is meant for Python 2, it is no longer used in Python 3. The standard module is now called urllib (you can find the documentation for it here: https://docs.python.org/3/library/urllib.html).

Try this instead:

import urllib.request
req=urllib.request.Request(api_url,binary_data,header)
f=urllib.request.urlopen(req)

urllib.request.Request(): https://docs.python.org/3/library/urllib.request.html#urllib.request.Request urllib.request.urlopen():https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen


Upvotes: 2

Related Questions