Iulian T.
Iulian T.

Reputation: 11

Why this error with pyinstaller and urllib?

I'm trying to make a windows executable of a python script. In the Spyder console everything is fine, however when I package it with pyinstaler it doesn't work.

import urllib.request
f = urllib.request.urlopen('http://www.python.org/')
print(f.read(100))

Result in Spyder console:

b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xed}\xdbr\x1bG\xd2\xe6\xbd"\xe6\x1d\xcaP\x8cH\x8d\xd98\xf1(\x8a\x84G\x07J\xa2G\'\x9b\x94\xf5\xcf\xef\xdf\xa1h\xa0\x1b@\x93@7\xd4\x07\x92\xf0\xcc<\xc2F\xec\xf5\xdel\xec{\xec\xdd\xbe\xc9>\xc1>\xc2~\x99U\xd5]\xdd\xe8n\x00\x12\xad\xb1#4\x1e\x9b\xe8SUVVV\x9e*3'

Packed with:

.\pyinstaller --onefile --console program.py

I get the following error:

PS C:\Users\User\anaconda3\Scripts\dist> .\program
Traceback (most recent call last):
  File "program.py", line 2, in <module>
  File "urllib\request.py", line 216, in urlopen
  File "urllib\request.py", line 525, in open
  File "urllib\request.py", line 634, in http_response
  File "urllib\request.py", line 557, in error
  File "urllib\request.py", line 496, in _call_chain
  File "urllib\request.py", line 749, in http_error_302
  File "urllib\request.py", line 519, in open
  File "urllib\request.py", line 541, in _open
  File "urllib\request.py", line 496, in _call_chain
  File "urllib\request.py", line 1419, in unknown_open
urllib.error.URLError: <urlopen error unknown url type: https>
[PYI-14392:ERROR] Failed to execute script 'program' due to unhandled exception!

Upvotes: 0

Views: 34

Answers (0)

Related Questions