I am using the urllib Python library to make a GET request to https://hub.docker.com just to check basic connectivity. It was working fine until last week. Now I am getting a 403 Forbidden error unless I add a User-Agent header.
Did Docker recently add this restriction? I couldn’t find any release notes about this change. it’s causing issues on our side. Any information would be helpful.
This doesn’t work, gives 403 HTTPError
import urllib.request
url = "https://hub.docker.com"
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
print(response.code)
This works
import urllib.request
url = "https://hub.docker.com"
headers = {"User-Agent": "YourCustomUserAgent"}
request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)
print(response.code)