The error is:

urllib.error.HTTPError: HTTP Error 403: Forbidden

I solved it using this piece of code when raising this error

import urllib.request
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}' ',
}
proxy_support = urllib.request.ProxyHandler(HTTP_PROXIES)
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)

and then
results = sparql.query().convert()

I think this solved my issue allowing using proxy to make a call thought 
SparqlWrapper

On Tuesday, 26 November 2024 at 08:25:18 UTC+1 carlo...@gmail.com wrote:

> Hi Mario,
>
> could you share the error returned?
>
> Best,
>
> Carlos
>
> On Friday, November 22, 2024 at 5:10:38 PM UTC+1 Mario Migliaccio wrote:
>
>> Just to give an example I'm using this code to query data from official 
>> endpoint from Italian assembly. I am having trouble with the connection of 
>> my production environment. I am wondering if it is possibile to query 
>> through a proxy I have
>> having
>> PROXY_PORT
>> PROXY_HOST
>> PROXY_PASSWORD
>> PROXY_USER
>>
>> sparql_endpoint = "https://dati.senato.it/sparql";
>> sparql = SPARQLWrapper(sparql_endpoint)
>> sparql.setQuery("""
>> PREFIX osr: <http://dati.senato.it/osr/>
>> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
>>
>> SELECT DISTINCT ?senatore ?nome ?cognome ?inizioMandato ?legislatura 
>> ?tipoMandato
>> WHERE {
>>     ?senatore a osr:Senatore.
>>     ?senatore foaf:firstName ?nome.
>>     ?senatore foaf:lastName ?cognome.
>>     ?senatore osr:mandato ?mandato.
>>     ?mandato osr:legislatura ?legislatura.
>>     ?mandato osr:inizio ?inizioMandato.
>>     ?mandato osr:tipoMandato ?tipoMandato.
>>     OPTIONAL { ?mandato osr:fine ?df. }
>>     FILTER(!bound(?df))
>> } ORDER BY ?cognome ?nome
>> """)
>> sparql.setReturnFormat(JSON)
>> sparql.setTimeout(10)
>> sparql.query().convert()
>> On Friday, 22 November 2024 at 17:06:07 UTC+1 Mario Migliaccio wrote:
>>
>>> I am wondering if there's the possibility to query the endpoint throgh a 
>>> proxy.
>>>
>>> Is it possibile?
>>>
>>

-- 
http://github.com/RDFLib
--- 
You received this message because you are subscribed to the Google Groups 
"rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rdflib-dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/rdflib-dev/1d03b6af-e9e0-4b76-8027-89ac39f82ca5n%40googlegroups.com.

Reply via email to