Python : SpaqrlWrapper, Timeout? - python

I am new to python as well as new to the world of querying the semantic web.
I am using SPARQLWrapper library to query dbpedia, I searched the library documentation but failed to find 'timeout' for a query fired to dbpedia from sparqlWrapper.
Anyone has any idea about the same.

As of 2018, you can use SPARQLWrapper.setTimeout() to set the timeout for SPARQLWrapper requests.

As Karoo mentioned you can use SPARQLWrapper.setTimeout(timeout=(int)).
If you want a timeout as a float, go to the Wrapper.py module and change self.timeout = int(timeout) to self.timeout = float(timeout) in the def setTimeout(self, timeout): function.

I don't know if this is specifically an answer for your question, but I searched for it for ages and heres my solution for anyone else having trouble with Virtuoso specific timeouts on SPARQLWrapper:
Your can use this line of code to set a server-side timeout for your queries (not clientside like .setTimeout):
[your SPARQLWrapper entity].addExtraURITag("timeout","[your timeout in ms]")
In my case it looks like this:
s.addExtraURITag("timeout","10000")
This should give you 10 seconds of time before your query stops searching and returns results instead of just giving you a Timeout error.
Hope I could help anyone.

DBPedia uses Virtuoso server for it's endpoint and timeout is a virtuoso-specific option. SparqlWrapper doesn't currently support it.
Next version will feature better modularity and proper vendor-specific extensions might be implemented after that, but I guess you don't have time to wait.
Currently, the only way to add such parameter is to manually hardcode it into your local version of library

Related

PyModbus - trigger an action/function when holding register is read

I've setup a running Pymodbus server based on the 'Updating Server' (v2.5.3) example.
https://pymodbus.readthedocs.io/en/v2.5.3/source/example/updating_server.html
Everything works ok.
Now i want to trigger a function (which will simply increment a value by 1), when (any) client is requesting to read/poll the contents of the holdingregisters.
Console output, when client requests function code 3
My knowledge of Pymodbus is limited, so any help would be great.
There is likely a way to overload the StartTCPServer function, though looking through the source code it seems tricky since it's built on asyncio (not like that's bad, just less conducive to easily overloading this one thing you're trying to do).
However there are several modbus libraries you can use, and sourceperl's pyModbusTCP makes it very easy to do exactly what you're trying to do. Check out the example https://github.com/sourceperl/pyModbusTCP/blob/master/examples/server_change_log.py
There they use the built-in hooks for doing just that, but you can get easily overload any part of the server if you wanted to for example capture the incoming modbus message before it gets processed.

TooManyRequests Overpass Error

I'm using overpy to query the Overpass API, and the nature of the data is such that I have a lot of queries to execute. I've run into the 429 OverpassTooManyRequests exception and I'm trying to play by the rules. I've tried introducing time.sleep methods to space out the requests, but I have no basis for how long the program should wait before continuing.
I found this link which mentions a "Retry-after" header:
How to avoid HTTP error 429 (Too Many Requests) python
Is there a way to access that header in an overpy response? I've been through the docs and the source code, but nothing stood out that would allow me to access that header so I can pause querying until it's acceptable to do so again.
I'm using Python 3.6 and overpy 0.4.
Maybe this isn't quite the answer you're seeking, but I ran into the same issue and fixed it by simply hosting my own OSM database server using docker. Just clone the repo and follow instructions:
https://github.com/mediasuitenz/docker-overpass-api
from http://overpass-api.de/command_line.html do check that you do not have a single 'runaway' request that is taking up all the resources.
After verifying that I don't have runaway queries, I have taken Peter's advice and added a catch for the TooManyRequests exception that waits 30s and tries again. This seems to be working as an immediate solution.
I will also raise an issue with the originators of OverPy to suggest an enhancement to allow evaluating the /api/status, as per mmd's advice.

How to set timeout on SUDS connection

I'm struggling with what should be a very simple problem. I'm failing to set the session timeout on a SUDS jurko connection. My WSDL is good. Everything works when pulling a smaller dataset. I've attempted several means of setting the timeout. While the following doesn't complain/etc, it also is ineffective:
from suds.client import Client
client = Client(authUrl, timeout=600)
My connection/etc appears to fail after the default 90 seconds. Unfortunately, this just isn't long enough to get the data I need. The error I receive is
ssl.SSLError: ('The read operation timed out',)
Help! My Google foo is weak, I guess. I've tried many things... and, finally, I have to ask for help. Which will be greatly appreciated...
While this will not help the OP I think that it is worth mentioning that under Python 3.9 the call to Client(...., timeout=300) seems to be working with sudz version 1.0.3 from https://github.com/Skylude/suds - so I guess that this issue has been resolved.

How to interface with opentsdb from Python

I'd like to interface with an opentsdb data store with Python. I only see a java client library for it. How would I go about this?
Unless you want a standalone client (in which case the Twisted Python OpenTSDB Client looks great), the easiest way is to run tcollector, and simply drop your Python script under /usr/local/tcollector/collector/0 – your script is expected to never return and print one data point per line in that format: metric timestamp value tag1=value1 tag2=value2 ....
tcollector takes care of connecting to OpenTSDB, pushing your data points out, etc. So you can focus on collecting the data you want to collect and write your data collection script in Python or any other scripting language you may like.
You can use Python request module and OpenTSDB HTTP API, too.
Give that library a try.
Twisted Python OpenTSDB Client
http://code.google.com/p/totsdb/source/browse/tostdb.py

Tools to Test RPC twisted calls?

Are there any Tools / Chrome plugins like "Advanced REST Plugin" for Chrome that I can use to Test Twisted RPC JSON calls?
Or do I have to write some Python code to do this?
When it comes to testing, you sould always use code, so that if you change something in the future or if you have to fix a bug, testing your changes will be a matter of seconds:
python mytestsuite.py

Categories