BallWarapol BallWarapol - 6 months ago 27
Python Question

Can't "import urllib.request, urllib.parse, urllib.error"

I trying to convert my project to python3.

My server script is

#!/usr/bin/env python

import http.server
import os, sys
server = http.server.HTTPServer
handler = http.server.CGIHTTPRequestHandler
server_address = ("", 8080)
#handler.cgi_directories = [""]
httpd = server(server_address, handler)

But when I try:

import urllib.request, urllib.parse, urllib.error

I get this in terminal of python3 ./

import urllib.request, urllib.parse, urllib.error
ImportError: No module named request - - [18/Sep/2016 22:47:18] CGI script exit status 0x100

How can I do this?


Your shebang suggests that code should be run by python binary, which is historically associated with Python 2.x releases.

Simply change first line to:

#!/usr/bin/env python3