I'm trying to use Python to search an InfluxDB database for data closely matching specific coordinates. I have converted all coordinates from lat/lon to plus codes (i.e. 9C4WXRRQ+69). In order to search InfluxDB for codes similar, I need to use RegEx, which requires me to escape the '+' character using a backslash.
When I send a query from Python, it adds a second backslash (which I know Python uses to display a single backslash) which then results in a failed query. Is there any way of sending a string query from Python with only a single backslash or should I stick to the "fudging it" method of removing all '+' signs from my codes and thereby negating the need?
I have tried the methods mentioned on the below questions, along with multiple others, but all send a double backslash.
Why can't Python's raw string literals end with a single backslash?
How to replace a double backslash with a single backslash in python?
In Influx CMD, I can use the following:
SELECT count(olc) FROM OLC WHERE olc =~ /9C4WXRRQ\+69*/
Which returns:
name: OLC
time count
---- -----
0 1104
However, if I send the same query from Python:
influx.query("SELECT count(olc) FROM OLC WHERE olc =~ /9C4WXRRQ\+69*/")
The InfluxDB readout gives the following (which shows the double backslash) and returns a blank response:
2019-01-17T14:20:28.849772Z info Executing query {"log_id": "0C~7QHG0000", "service": "query", "query": "SELECT count(olc) FROM olctest.autogen.OLC WHERE olc =~ /9C4WXRRQ\\+69*/"}
If I remove all '+' signs from the plus codes, the query works fine:
influx.query("SELECT count(olc) FROM OLC WHERE olc =~ /9C4WXRRQ69*/")
Resulting in:
ResultSet({'('OLC', None)': [{'time': '1970-01-01T00:00:00Z', 'count': 1104}]})
Which shows querying from Python is not the problem.