HTTPMOD JSON parsing error

Begonnen von Wolle02, 14 März 2021, 08:49:22

Vorheriges Thema - Nächstes Thema

Wolle02

Ich möchte gerne meinen Standort vom OSM Nominatim Server mit einer Adresse versehen lassen. Dazu habe ich folgendes HTTPMOD erstellt:

Internals:
   BUSY       0
   DEF        https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%% 0
   FUUID      604d0481-f33f-bf2d-5052-a65e8d98d80c88ed
   FVERSION   98_HTTPMOD.pm:0.236730/2021-02-04
   Interval   0
   MainURL    https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%
   ModuleVersion 4.1.02 - 4.2.2021
   NAME       Koordinatenort
   NOTIFYDEV  global
   NR         454
   NTFY_ORDER 50-Koordinatenort
   STATE      ???
   TYPE       HTTPMOD
   value     
   CompiledRegexes:
   HttpUtils:
     NAME       
     addr       https://nominatim.openstreetmap.org:443
     auth       0
     code       200
     compress   1
     conn       
     data       
     displayurl https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=9.183131
     header     
     host       nominatim.openstreetmap.org
     httpheader HTTP/1.1 200 OK
Server: nginx
Date: Sun, 14 Mar 2021 07:40:43 GMT
Content-Type: application/json; charset=UTF-8
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS,GET
     httpversion 1.0
     hu_blocking 0
     hu_filecount 1
     hu_port    443
     hu_portSfx
     ignoreredirects 1
     loglevel   4
     path       /reverse?format=json&lat=48.786868&lon=9.183131
     protocol   https
     redirects  0
     timeout    2
     url        https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=9.183131
     sslargs:
   QUEUE:
   READINGS:
   REQUEST:
     context    reading
     data       
     header     
     ignoreredirects 0
     num        0
     retryCount 0
     type       update
     url        https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%
Attributes:
   enableControlSet 1
   extractAllJSON 1
   replacement01Mode expression
   replacement01Regex %%lat%%
   replacement01Value {ReadingsVal("Geopositionen","Wolle_latitude","")}
   replacement02Mode expression
   replacement02Regex %%lon%%
   replacement02Value {ReadingsVal("Geopositionen","Wolle_longitude","")}


Bei einem reread steht mit einem verbose 5 folgendes im Logfile:

2021.03.14 08:40:43 5: Koordinatenort: set called with reread
2021.03.14 08:40:43 4: Koordinatenort: GetUpdate called (reread)
2021.03.14 08:40:43 5: Koordinatenort: AddToQueue adds type update to URL https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%, no data, no headers, retry 0, initial queue len: 0
2021.03.14 08:40:43 5: Koordinatenort: HandleSendQueue called from AddToSendQueue, qlen = 1
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lat%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_latitude","")} input:
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lon%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_longitude","")} input:
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lat%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_latitude","")} input:
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lon%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_longitude","")} input:
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lat%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_latitude","")} input: https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%
2021.03.14 08:40:43 5: Koordinatenort: Replace: match for type update, regex (?^:%%lat%%), mode expression, value package main; {ReadingsVal("Geopositionen","Wolle_latitude","")}, input: https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%, result is https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=%%lon%%
2021.03.14 08:40:43 5: Koordinatenort: Replace called for type update, regex (?^:%%lon%%), mode expression, value {ReadingsVal("Geopositionen","Wolle_longitude","")} input: https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=%%lon%%
2021.03.14 08:40:43 5: Koordinatenort: Replace: match for type update, regex (?^:%%lon%%), mode expression, value package main; {ReadingsVal("Geopositionen","Wolle_longitude","")}, input: https://nominatim.openstreetmap.org/reverse?format=json&lat=%%lat%%&lon=%%lon%%, result is https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=9.183131
2021.03.14 08:40:43 4: Koordinatenort: HandleSendQueue sends update with timeout 2 to https://nominatim.openstreetmap.org/reverse?format=json&lat=48.786868&lon=9.183131, No Data, No Header
2021.03.14 08:40:43 5: Koordinatenort: ReadCallback called from __ANON__
2021.03.14 08:40:43 4: Koordinatenort: Read callback: request type was update retry 0,
header: HTTP/1.1 200 OK
Server: nginx
Date: Sun, 14 Mar 2021 07:40:43 GMT
Content-Type: application/json; charset=UTF-8
Connection: close
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: OPTIONS,GET, body length 622
2021.03.14 08:40:43 5: Koordinatenort: Read callback: body
{"place_id":259213274,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":7106566,"lat":"48.7800357","lon":"9.1635957","display_name":"Hauptsammler West, Kriegsbergstraße, Hauptbahnhof, Stuttgart-Mitte, Stuttgart, Baden-Württemberg, 70174, Deutschland","address":{"man_made":"Hauptsammler West","road":"Kriegsbergstraße","neighbourhood":"Hauptbahnhof","suburb":"Stuttgart-Mitte","city":"Stuttgart","state":"Baden-Württemberg","postcode":"70174","country":"Deutschland","country_code":"de"},"boundingbox":["48.7679397","48.7900731","9.137463","9.1929978"]}
2021.03.14 08:40:43 4: Koordinatenort: BodyDecode found charset header and set decoding to UTF-8 (bodyDecode was set to auto)
2021.03.14 08:40:43 4: Koordinatenort: BodyDecode is decoding the response body as UTF-8
2021.03.14 08:40:43 3: Koordinatenort: error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 38 (before "\x{fffd} OpenStreetM...") at lib/FHEM/HTTPMOD/Utils.pm line 668.

2021.03.14 08:40:43 5: Koordinatenort: GetCookies is looking for Cookies
2021.03.14 08:40:43 5: Koordinatenort: ExtractSid called, context reading, num 0
2021.03.14 08:40:43 4: Koordinatenort: checking for redirects, code=200, ignore=0
2021.03.14 08:40:43 4: Koordinatenort: no redirects to handle
2021.03.14 08:40:43 5: Koordinatenort: Read callback sets LAST_REQUEST to update
2021.03.14 08:40:43 5: Koordinatenort: CheckAuth decided no authentication required
2021.03.14 08:40:43 3: Koordinatenort: no parsed JSON structure available
2021.03.14 08:40:43 5: Koordinatenort: Read starts parsing response to update with defined readings:
2021.03.14 08:40:43 4: Koordinatenort: Read response to update didn't match any Reading
2021.03.14 08:40:43 5: Koordinatenort: HandleSendQueue called from ReadCallback, qlen = 0
2021.03.14 08:40:43 5: Koordinatenort: HandleSendQueue found no usable entry in queue


Die Ersetzung der Koordinaten scheint korrekt zu funktionieren, aber er hat wohl ein Problem beim JSON extrahieren.
Wenn ich das richtig interpretiere schein das hier das Problem zu sein:

2021.03.14 08:40:43 3: Koordinatenort: error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 38 (before "\x{fffd} OpenStreetM...") at lib/FHEM/HTTPMOD/Utils.pm line 668.

Er mag wohl das © nicht.

Was kann ich hier tun?

StefanStrobel

Hallo,

hast Du die aktuellste Version vom HTTPMOD-Modul?
bodyDecode stand mal per default auf auto, aber bei JSON-Daten hat das genau zu so einem Fehler geführt.
daher habe ich das vor kurzem wieder geändert, so dass bodyDecode per Default auf none steht.

Gruss
   Stefan

Wolle02

#2
Hallo Stefan,

aber warum versucht er dann trotzdem UTF-8 zu dekodieren, wenn das Attribut per default auf none steht? Die Fehlermeldung lautet ja:

2021.03.14 08:40:43 3: Koordinatenort: error while parsing JSON data: malformed UTF-8 character in JSON string, at character offset 38 (before "\x{fffd} OpenStreetM...") at lib/FHEM/HTTPMOD/Utils.pm line 668.

Oder versteh ich das falsch?

Jedenfalls habe ich jetzt mal das Attribut bodyDecode auf ISO-8859-1 gestellt; damit funktioniert es nun tatsächlich.


Edit:
Ich habe die Modulversion 4.1.02 - 4.2.2021

StefanStrobel

Hallo Wolle02,

mach morgen einfach nochmal ein Update, dann bekommst Du die aktuelle Version und die aktuelle Utils.pm dazu. Da ist bodyDefault dann sicher per Default auf none.
Um sicher zu gehen kannst Du es aber auch selbst auf 'none' setzen. Am 4.2. könnte es noch die alte Variante gewesen sein.
Ob ISO8859-1 in Deinem Fall sinnvoll ist kann ich nicht sagen.

Gruss
   Stefan

Wolle02

Ok, jetzt wird mir die Version 4.1.05 - 6.3.2021 angezeigt und im Logfile steht kein ParsingError mehr. Allerdings werden die Sonderzeichen und Umlaute nicht richtig dekodiert.

ZitatOb ISO8859-1 in Deinem Fall sinnvoll ist kann ich nicht sagen.

Damit werden die Sonderzeichen und Umlaute zumindest korrekt dekodiert, also habe ich dies als Attribut mal wieder mit reingenommen.

Das Ergebnis sieht jetzt gut aus.