Python Forum

Full Version: Error Code: 1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hiya - Have been trying to run urllib but have been encountering errors - I have delved into it, it appears that I do not have the http package installed. However, since then I have installed - setup tools, wheel, eztools & ezsetup with all versions up to date (pip also up to date) - I still get the same error message when trying to install http 'python setup.py egg_info id not run successfully exit code:1

any help would be much appreciated :)

Output:
pip install http Collecting http Using cached http-0.02.tar.gz (32 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [8 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/private/var/folders/21/2vw8yk_91sd3zjl_gz3pmzmh0000gp/T/pip-install-gub65jb9/http_c4f776f02b624ac0b46128b1b7ff4c9c/setup.py", line 3, in <module> import http File "/private/var/folders/21/2vw8yk_91sd3zjl_gz3pmzmh0000gp/T/pip-install-gub65jb9/http_c4f776f02b624ac0b46128b1b7ff4c9c/http/__init__.py", line 17, in <module> from request import Request ModuleNotFoundError: No module named 'request' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
This is package that is not updated since 2012

I don't think you want to install it.
What python version do you use? Also show your code where you try use urllib, incl. full traceback you get.
(Nov-07-2023, 11:41 AM)buran Wrote: [ -> ]This is package that is not updated since 2012

I don't think you want to install it.
What python version do you use? Also show your code where you try use urllib, incl. full traceback you get.




Python version 3.12.0

code used:

import urllib3.request

fhand = urllib3.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
    print(line.decode().strip())
It pulls back the contents for a completely different website:

HTTP/1.1 200 OK
Date: Tue, 07 Nov 2023 12:07:45 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Sat, 13 May 2017 11:22:22 GMT
ETag: "1d3-54f6609240717"
Accept-Ranges: bytes
Content-Length: 467
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Connection: close
Content-Type: text/plain

Why should you learn to write programs?

Writing programs (or programming) is a very creative
and rewarding activity. You can write programs
for
many reasons, ranging from making your living to solving
a difficult data analysis problem to having fun to helping
someone else solve a problem. This book assumes that
everyone needs to know how to program, and that once
you know how to program you will figure out what you want
to do with your newfound skills.

Error:
Traceback (most recent call last): File "/Users//Documents/pyfe/ex_12_01/urllib.py", line 1, in <module> import urllib3.request File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module> from . import exceptions File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module> from http.client import IncompleteRead as httplib_IncompleteRead ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
Use Requests for this.
import requests

url = "https://data.pr4e.org/romeo.txt"
response = requests.get(url)
print(response.status_code)
print(response.text.strip())

# Download the file
with open('romeo.txt', 'wb') as fp:
    fp.write(response.content)
Output:
200 But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief
(Nov-07-2023, 12:36 PM)snippsat Wrote: [ -> ]Use Requests for this.
import requests

url = "https://data.pr4e.org/romeo.txt"
response = requests.get(url)
print(response.status_code)
print(response.text.strip())

# Download the file
with open('romeo.txt', 'wb') as fp:
    fp.write(response.content)
Output:
200 But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief

For some bizarre reason, I am getting the same result... any ideas?

import requests
 
url = "https://data.pr4e.org/romeo.txt"
response = requests.get(url)
print(response.status_code)
print(response.text.strip())
 
# Download the file
with open('romeo.txt', 'wb') as fp:
    fp.write(response.content)
Error:
Traceback (most recent call last): File "/Users/Documents/pyfe/ex_12_01/test2.py", line 1, in <module> import requests File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module> from . import exceptions File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module> from http.client import IncompleteRead as httplib_IncompleteRead ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
Couple of issues with your code:

1. Don't name your file urllib.py
2. [It look like] you want to use urllib.requests from standard library, not third-party package urllib3 which you have to install via pip and which does not have urllib3.request.urlopen

import urllib.request
 
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
    print(line.decode().strip())
All that said, and as recommended in the docs and also by @snippsat - install and use requests package
(Nov-07-2023, 12:54 PM)percyy30 Wrote: [ -> ]For some bizarre reason, I am getting the same result... any ideas?
Uninstall the package that you installed first
pip uninstall http
(Nov-07-2023, 12:57 PM)Gribouillis Wrote: [ -> ]
(Nov-07-2023, 12:54 PM)percyy30 Wrote: [ -> ]For some bizarre reason, I am getting the same result... any ideas?
Uninstall the package that you installed first
pip uninstall http

Uninstalled :)
(Nov-07-2023, 12:54 PM)percyy30 Wrote: [ -> ]
(Nov-07-2023, 12:36 PM)snippsat Wrote: [ -> ]Use Requests for this.
import requests

url = "https://data.pr4e.org/romeo.txt"
response = requests.get(url)
print(response.status_code)
print(response.text.strip())

# Download the file
with open('romeo.txt', 'wb') as fp:
    fp.write(response.content)
Output:
200 But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief

For some bizarre reason, I am getting the same result... any ideas?

import requests
 
url = "https://data.pr4e.org/romeo.txt"
response = requests.get(url)
print(response.status_code)
print(response.text.strip())
 
# Download the file
with open('romeo.txt', 'wb') as fp:
    fp.write(response.content)
Error:
Traceback (most recent call last): File "/Users/Documents/pyfe/ex_12_01/test2.py", line 1, in <module> import requests File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module> from . import exceptions File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module> from http.client import IncompleteRead as httplib_IncompleteRead ModuleNotFoundError: No module named 'http.client'; 'http' is not a package

Thanks for getting back to me (file names changed) - I have uninstalled urllib3 and used the code you provided and get the following output and traceback:

Output:
HTTP/1.1 200 OK Date: Tue, 07 Nov 2023 13:04:36 GMT Server: Apache/2.4.18 (Ubuntu) Last-Modified: Sat, 13 May 2017 11:22:22 GMT ETag: "1d3-54f6609240717" Accept-Ranges: bytes Content-Length: 467 Cache-Control: max-age=0, no-cache, no-store, must-revalidate Pragma: no-cache Expires: Wed, 11 Jan 1984 05:00:00 GMT Connection: close Content-Type: text/plain Why should you learn to write programs? Writing programs (or programming) is a very creative and rewarding activity. You can write programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem. This book assumes that everyone needs to know how to program, and that once you know how to program you will figure out what you want to do with your newfound skills.
Error:
Traceback (most recent call last): File "/Users/Documents/pyfe/ex_12_01/test3.py", line 1, in <module> import urllib.request File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 88, in <module> import http.client ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
I have also installed urllib3 and I get the following output & traceback:
Output:
HTTP/1.1 200 OK Date: Tue, 07 Nov 2023 13:06:27 GMT Server: Apache/2.4.18 (Ubuntu) Last-Modified: Sat, 13 May 2017 11:22:22 GMT ETag: "1d3-54f6609240717" Accept-Ranges: bytes Content-Length: 467 Cache-Control: max-age=0, no-cache, no-store, must-revalidate Pragma: no-cache Expires: Wed, 11 Jan 1984 05:00:00 GMT Connection: close Content-Type: text/plain Why should you learn to write programs? Writing programs (or programming) is a very creative and rewarding activity. You can write programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem. This book assumes that everyone needs to know how to program, and that once you know how to program you will figure out what you want to do with your newfound skills.
Error:
Traceback (most recent call last): File "/Users/olliepercival/Documents/pyfe/ex_12_01/test2.py", line 1, in <module> import requests File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module> from . import exceptions File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module> from http.client import IncompleteRead as httplib_IncompleteRead ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
(Nov-07-2023, 12:54 PM)buran Wrote: [ -> ]Couple of issues with your code:

1. Don't name your file urllib.py
2. [It look like] you want to use urllib.requests from standard library, not third-party package urllib3 which you have to install via pip and which does not have urllib3.request.urlopen

import urllib.request
 
fhand = urllib.request.urlopen('http://data.pr4e.org/romeo.txt')
for line in fhand:
    print(line.decode().strip())
All that said, and as recommended in the docs and also by @snippsat - install and use requests package

Thanks for getting back to me (file names changed) - I have uninstalled urllib3 and used the code you provided and get the following output and traceback:

Output:
HTTP/1.1 200 OK Date: Tue, 07 Nov 2023 13:04:36 GMT Server: Apache/2.4.18 (Ubuntu) Last-Modified: Sat, 13 May 2017 11:22:22 GMT ETag: "1d3-54f6609240717" Accept-Ranges: bytes Content-Length: 467 Cache-Control: max-age=0, no-cache, no-store, must-revalidate Pragma: no-cache Expires: Wed, 11 Jan 1984 05:00:00 GMT Connection: close Content-Type: text/plain Why should you learn to write programs? Writing programs (or programming) is a very creative and rewarding activity. You can write programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem. This book assumes that everyone needs to know how to program, and that once you know how to program you will figure out what you want to do with your newfound skills.
Error:
Traceback (most recent call last): File "/Users/Documents/pyfe/ex_12_01/test3.py", line 1, in <module> import urllib.request File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 88, in <module> import http.client ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
I have also installed urllib3 (using code provided by @snippsat and I get the following output & traceback:

Output:
HTTP/1.1 200 OK Date: Tue, 07 Nov 2023 13:06:27 GMT Server: Apache/2.4.18 (Ubuntu) Last-Modified: Sat, 13 May 2017 11:22:22 GMT ETag: "1d3-54f6609240717" Accept-Ranges: bytes Content-Length: 467 Cache-Control: max-age=0, no-cache, no-store, must-revalidate Pragma: no-cache Expires: Wed, 11 Jan 1984 05:00:00 GMT Connection: close Content-Type: text/plain Why should you learn to write programs? Writing programs (or programming) is a very creative and rewarding activity. You can write programs for many reasons, ranging from making your living to solving a difficult data analysis problem to having fun to helping someone else solve a problem. This book assumes that everyone needs to know how to program, and that once you know how to program you will figure out what you want to do with your newfound skills.

Error:
Traceback (most recent call last): File "/Users/olliepercival/Documents/pyfe/ex_12_01/test2.py", line 1, in <module> import requests File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 13, in <module> from . import exceptions File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 7, in <module> from http.client import IncompleteRead as httplib_IncompleteRead ModuleNotFoundError: No module named 'http.client'; 'http' is not a package
Pages: 1 2