Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query through a proxy #240

Open
salander93 opened this issue Nov 28, 2024 · 0 comments
Open

Query through a proxy #240

salander93 opened this issue Nov 28, 2024 · 0 comments

Comments

@salander93
Copy link

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()
salander93 added a commit to salander93/sparqlwrapper that referenced this issue Nov 28, 2024
added into How To example of using a proxy RDFLib#240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant