OpenHab HTTP-Binding - Exception: Conversion = '2'

Hey guys, this is my google Maps Item:

String   GoogleMaps_me_distance              "Distanz [%s]"      { http="<[https://maps.googleapis.com/maps/api/distancematrix/json?origins=XXXXXl&destinations=YYYYYYYY&language=DE&departure_time=now&traffic_model=best_guess&mode=driving&key=XXXXXXXXXXXXXXXXXXXXXX:900000:JS(maps_1.js)]" }`

Transformation:

JSON.parse(input).rows[0].elements[0].distance.text;`

and i get this Eroor in my Log

2019-12-20 10:41:01.707 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service

    java.util.UnknownFormatConversionException: Conversion = '2'

    at java.util.Formatter.checkText(Formatter.java:2579) ~[?:1.8.0_222]

    at java.util.Formatter.parse(Formatter.java:2565) ~[?:1.8.0_222]

    at java.util.Formatter.format(Formatter.java:2501) ~[?:1.8.0_222]

    at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_222]

    at java.lang.String.format(String.java:2940) ~[?:1.8.0_222]

    at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:148) ~[?:?]

    at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]

    at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]

Looking Forward to get help from one of you guys :slightly_smiling_face:

Have you tried to use the JSONPATH transform?

Yes, didn’t worked as well.
When i try to get an answer from google in the Browser everything works fine.

String   GoogleMaps_me_distance              "Distanz [%s]"      { http="<[https://maps.googleapis.com/maps/api/distancematrix/json?origins=xxxxyx,+14558+xxxx&destinations=xxxxx+Gmbh+%26+Co+Kg,+xxxxx,+Berlin&language=DE&departure_time=now&traffic_model=best_guess&mode=driving&key=xxxxxxxxxxxx-xxxxxxxxxxxxxxxx:900000:JSONPATH($.rows[0].elements[0].distance.text)]" }

error in the log:

2019-12-20 22:03:04.234 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.UnknownFormatConversionException: Conversion = '2'
	at java.util.Formatter.checkText(Formatter.java:2579) ~[?:1.8.0_222]
	at java.util.Formatter.parse(Formatter.java:2565) ~[?:1.8.0_222]
	at java.util.Formatter.format(Formatter.java:2501) ~[?:1.8.0_222]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_222]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_222]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:148) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]

This is caused by +%26+ in the URL, which represents the escaped & character in URLs. The String.format method doesn’t like that since % has a special meaning for that method.

btw: You should edit your last post if the addresses are non fictional.

Bottom line: Just remove the mentioned part in the URL, your destination will be found by google maps anyway.

Cheers

Thank you very much. :slight_smile: Totally forgot to edit the key and address. Thanks for the hint :pray:

No problem, glad I could help. :slight_smile: you might consider marking my answer as “solution”, so the thread gets marked as solved.

Your hint was quite good, i don’t have the error anymore, but sadly it still isn’t working.

My current item:

String   GoogleMaps_me_distance              "Distanz [%s]"      { http="<[https://maps.googleapis.com/maps/api/distancematrix/json?origins=XXXXXXXXXXXX+4,+14558+Nuthetal&destinations=XXXXX,+XXXXXXX,+Berlin&language=DE&departure_time=now&traffic_model=best_guess&mode=driving&key=XXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXX:900000:JSONPATH($.rows[0].elements[0].distance.text)]" }

The URL works for sure

and now i get this error:

2019-12-22 14:36:16.088 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.lang.IllegalArgumentException: Invalid uri 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=XXXXXXXXXX+4,+14558+Nuthetal&destinations=XXXXXXX,+XXXXXXXXXXXX,+Berlin&language=DE&departure_time=now&traffic_model=best_guess&mode=driving&key=XXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXX': Invalid query
	at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222) ~[bundleFile:?]
	at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89) ~[bundleFile:?]
	at org.openhab.io.net.http.HttpUtil.createHttpMethod(HttpUtil.java:303) ~[bundleFile:?]
	at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:164) ~[bundleFile:?]
	at org.openhab.io.net.http.HttpUtil.executeUrl(HttpUtil.java:129) ~[bundleFile:?]
	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:176) ~[?:?]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:146) ~[bundleFile:?]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:169) [bundleFile:?]

This indicates that something in the URL after json? is invalid. Make sure you replace ß in Straße to ss.

1 Like

That’s it, thank you so much, everything work’s fine now. :slight_smile: