-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
I am receving a
urllib.error.HTTPError: HTTP Error 403: Forbidden
that could be solved if we use a proxy to send the request.
However it seems there is no direct implementation on using http proxy, but there's already issue on this topic opened years ago
#86 and #114 and which they have their PRs.
A solution was given with this PR
A solution then is:
import urllib.request
# Set proxies
HTTP_PROXIES = {
'http': f'http://{PROXY_USER}:{PROXY_PASSWORD}@'
f'{PROXY_HOST}:{PROXY_PORT}',
'https': f'https: //{PROXY_USER}:{PROXY_PASSWORD}@'
f'{PROXY_HOST}:{PROXY_PORT}' ',
}
# Activate proxy
proxy_support = urllib.request.ProxyHandler(HTTP_PROXIES)
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
# Sparql query
sparql_endpoint = <your_endpoint>
sparql = SPARQLWrapper(sparql_endpoint)
sparql.setQuery("<your_query>")
sparql.setReturnFormat(JSON)
sparql.setTimeout(10)
sparql.query().convert()
Metadata
Metadata
Assignees
Labels
No labels