You need to use from urllib.request import urlopen, also I suggest you use the with statement while opening a connection.

from urllib.request import urlopen

with urlopen("https://sunlightlabs.github.io/congress/legislators?api_key='(myapikey)") as conn:
    # dosomething
Answer from Sede on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › howto › urllib2.html
HOWTO Fetch Internet Resources Using The urllib Package — Python 3.14.3 documentation
In its simplest form you create a Request object that specifies the URL you want to fetch. Calling urlopen with this Request object returns a response object for the URL requested.
🌐
Real Python
realpython.com › urllib-request
Python's urllib.request for HTTP Requests – Real Python
January 11, 2025 - To get started, you’ll make a request to www.example.com, and the server will return an HTTP message. Ensure that you’re using Python 3 or above, and then use the urlopen() function from urllib.request:
🌐
Python
docs.python.org › 3 › library › urllib.request.html
urllib.request — Extensible library for opening URLs — Python ...
For example, Mozilla Firefox may identify itself as "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11", while urllib’s default user agent string is "Python-urllib/2.6" (on Python 2.6).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-urllib-module
Python Urllib Module - GeeksforGeeks
July 12, 2025 - ParseResult(scheme='https', netloc='www.geeksforgeeks.org', path='/python-langtons-ant/', params='', query='', fragment='') https://www.geeksforgeeks.org/python/python-langtons-ant/ Note:- The different components of a URL are separated and ...
🌐
Python
docs.python.org › 3 › library › urllib.html
urllib — URL handling modules
Source code: Lib/urllib/ urllib is a package that collects several modules for working with URLs: urllib.request for opening and reading URLs, urllib.error containing the exceptions raised by urlli...
🌐
Python Programming
pythonprogramming.net › urllib-tutorial-python-3
Python urllib tutorial for Accessing the Internet
This is how Google Analytics knows what browser you are using, for example. Within the header, there is a value called user-agent, which defines the browser that is accessing the website's server. If you are using the default python user-agent with urllib, then you are announcing yourself as Python-urllib/3.4, if your Python version is 3.4.
🌐
Nicolasbouliane
nicolasbouliane.com › blog › python-3-urllib-examples
Python 3 urllib examples - Nicolas Bouliane
import urllib.request response = urllib.request.urlopen('https://nicolasbouliane.com') headers = response.getheaders() content_type = response.getheader('Content-Type') print(headers) # [('Content-Type', 'text/html; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ...] print(content_type) ...
Find elsewhere
🌐
Real Python
realpython.com › ref › stdlib › urllib
urllib | Python Standard Library – Real Python
The urllib package is a staple for networking tasks in Python. ... >>> import urllib.request >>> response = urllib.request.urlopen("http://www.example.com") >>> html = response.read() >>> html[:60] b'<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>'
🌐
ArjanCodes
arjancodes.com › blog › using-python-urllib-module-for-web-scraping-and-url-parsing
Web Scraping and URL Parsing Made Easy with Python’s urllib | ArjanCodes
July 29, 2024 - Python’s urllib module is a powerful and versatile library for working with URLs and handling various internet-related tasks. It provides a range of functionalities, from fetching data from the web to parsing URLs. In this blog post, we’ll explore the key features of the urllib module, covering its submodules and demonstrating practical examples to help you master its usage.
🌐
Python Module of the Week
pymotw.com › 2 › urllib
urllib – simple interface for network resource access - Python Module of the Week
There are two Windows examples, with and without the drive letter at the prefix of the path. $ python urllib_pathnames.py == Default == Original: /a/b/c URL : /a/b/c Path : /d/e/f == Windows, without drive letter == Original: \a\b\c URL : /a/b/c Path : \d\e\f == Windows, with drive letter == Original: C:\\a\b\c URL : ///C:/a/b/c Path : \d\e\f
🌐
Pythonspot
pythonspot.com › urllib-tutorial-python-3
python urllib - Python Tutorial
Web browser A web-browsers sends their name and version along with a request, this is known as the user-agent. Python can mimic this using the code below.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python internet access using urllib.request and urlopen()
Python Internet Access Using Urllib.Request and Urlopen() | Simplilearn
October 9, 2024 - This article explains the Urllib python, urllib request urlopen() functions present in Python, which help in accessing the Internet using Python. Explore now.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Javatpoint
javatpoint.com › python-urllib-library
Python urllib Library - Javatpoint
Python urllib Library with Python with python, tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, operators, etc.
🌐
iO Flood
ioflood.com › blog › python-urllib
Python 'urllib' Library | Guide to Fetching URLs
February 6, 2024 - For these tasks, you might need to use more advanced urllib features or alternative Python libraries. In the world of web browsing, redirects are commonplace. urllib can handle these without breaking a sweat. Here’s how you can use urllib to handle redirects: from urllib.request import urlopen url = 'http://example.com' response = urlopen(url) if response.geturl() != url: print('Redirected to', response.geturl()) # Output: # Redirected to http://www.iana.org/domains/example
🌐
Guru99
guru99.com › home › python › python internet access using urllib.request and urlopen()
Python Internet Access using Urllib.Request and urlopen()
August 12, 2024 - # # read the data from the URL and print it # import urllib.request # open a connection to a URL using urllib webUrl = urllib.request.urlopen('https://www.youtube.com/user/guru99com') #get the result code and print it print ("result code: " ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python 3 tutorial › python 3 urllib
Python 3 URLlib | What is python 3 urllib? | Modules with Examples
March 30, 2023 - Below are the modules of the python 3 urllib module are as follows. When we use urllib.request with urlopen, we can open the supplied URL. The below example shows urllib.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
TutorialsPoint
tutorialspoint.com › url-handling-python-modules-urllib
URL handling Python modules (urllib)
In the below example we check the different parts of the supplied URL.X · import urllib.parse url='https://tutorialspoint.com/python' value = urllib.parse.urlsplit(url) print(value)