Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.5.1 urllib has no attribute request

I have tried

import urllib.request 

or

import urllib 

The path for my urllib is /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/__init__.py

I am wondering where is urlopen, or is my python module pointing to the wrong file?

like image 978
user1999806 Avatar asked May 05 '16 04:05

user1999806


People also ask

Is Urllib included in Python 3?

The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.

What is urllib request in Python?

The urllib. request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. See also. The Requests package is recommended for a higher-level HTTP client interface.


1 Answers

According to this, you have to use the following:

import urllib.request 

The reason is:

With packages, like this, you sometimes need to explicitly import the piece you want. That way, the urllib module doesn't have to load everything up just because you wanted one small part.

like image 154
Swordsman Avatar answered Sep 24 '22 09:09

Swordsman