ValueError("No JSON object could be decoded") Python googlemaps - google-app-engine

I am using Google app engine (v1.9.24) with flask (v0.10.1) and python (v2.7.5).
I'm trying to get the googlemaps (v2.2) API to work with my app.
I know the JSON returned is badly formatted but I don't why.
My code is below:
import googlemaps
gmaps = googlemaps.Client(key='API_KEY')
geocode_result = gmaps.geocode('6b, oko awo, victoria island, lagos')
return geocode_result
This works perfectly, but returns a badly formatted JSON string (I confirmed this by running the same code on my local machine).
I used JSON validator to validate the JSON it returned. And because of the badly fomatted JSON my flask app crashes and gives me a ValueError.
I don't know a way around this and I'd appreciate any help.

The problem is not with the JSON. Actually,
gmaps.geocode('6b, oko awo, victoria island, lagos')
doesn't return JSON at all, it returns a list that holds the value of "result" as documented in the google docs, as you can see here in the source code for googlemaps library.
What is actually returned is a list object filled with data. All the string values inside this list are unicode strings. That means they look like u'hello' instead of plain "hello" (note the double quotes) that json.loads() expects (I assume that is how you are trying to load the JSON).
This probably means that the problem you're trying to solve a non existing problem. You don't have to load the JSON, because it already is a python list object.
You can confirm by doing
json.loads(json.dumps(geocode_result))
it works fine, meaning there is no problem with the JSON structure.

Related

can't show/display image from mongodb to directly react js component

I am new to MERN stack. I have already tried a lot of youtube videos and google searches to show/display the images stored in mongodb as the schema :
photograph: {
data : Buffer,
contentType : String
}
It saved successfully in mongodb after few efforts. I tried to convert it into base64 as done by other youtubers but still no results so far.
All of the commented out- (img tags) and array.map functions -> (because i tried to convert my data to array instead of json and then use .map function) are the things i have already tried. I am trying to understand the basics here. so please suggest me simple methods to do it. Also remember that {user.name} {user.dateOfBirth} , etc type of all other data showing successfully.

How do get the result from REST website that returns only text?

I'm trying to use a REST web service from Geonames.org. When I try to manually put in the url with the parameters, it would only return the Country Code. I've tried to search for ways to implement it, but most of what I've seen return JSON text with multiple keys and data. I feel like the answer should be pretty simple, but I'm unsure.
I'm trying to use this for a React project I'm working on.
Here is an example of what the url returns
Just looked into the docs of that API, and it says if you want to receive JSON responses simply add JSON keyword to the endpoint. Like here for given endpoint you have:
http://api.geonames.org/countryCodeJSON?formatted=true&lat=47.03&lng=10.2&username=demo
so just change countryCode to countryCodeJSON.
Source: http://www.geonames.org/export/JSON-webservices.html

Need help parsing through JSON Object in JMETER

I'm testing an application that calls one API, gets a bunch of work orders, then only the work order ID's are passed to another API to display on the page.
The format they need to be in is: {"workOrderIds":["12345","123456"]}
I'm using the JSON Extractor with the following Path Expressions:
$..workOrderNumber
then I'm using the JSR223 PostProcessor and using the following script:
props.put("workOrderNumber", "${workOrderNumber}";
The problem is, that its creating the object like so when I add the variable into the POST Request body of the second request:
{"workOrderIds":["12345, 123456"]}
essentially, I just need to make sure that each value has quotations, but not sure how to make this happen. Sorry if this seems simple, I'm fairly new to QA and have spent several hours trying to figure this out.
We cannot provide a comprehensive answer without seeing the source JSON, maybe it worth trying explicitly casting the filtering result to an Integer like:
vars.put('workOrderIds', new groovy.json.JsonBuilder(new groovy.json.JsonSlurper().parse(prev.getResponseData()).findResults { entry -> entry.workOrderNumber as int }).toPrettyString())
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Logic app turn the binary to bad character

I created a logic app which gets the data from restapi. The content type of data is Application/protobuf(protobuf is a binary data made by google https://developers.google.com/protocol-buffers/docs/tutorials) I know that LA uses base64 encoding so it changes the data to base64 encoding. As the data to be deserialised via protoc complier so it needed binary format. So i store this data into a variable and trying to paas this further processing. But unfortunately the data stores in variable changes into boxes and ? So protoc compiler fails to deserialised the same.
I tried base64tobinary and http() as per suggestion mentioned section "other content type" on microsoft https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-content-type#applicationxml-and-applica...
But it did not work. Can anybody help on this?
I tried reproducing the issue and found that the rest API body which we are receiving will be transformed back to string when we use string() i.e.. string(triggerBody()) dynamic expression.
Later, I convert to binary by using the dynamic expression 'binary', i.e. 'binary(outputs('Compose')', which will return a 'application/octet-stream' result. When I tried to convert back to a string, everything worked great for me.
Here is the flow of my logic app
and here is the output
I have changed the way of using. Instead of streaming, I am storing the data into file and processing further.

Obtaining Weather Data From NOAA

I am trying to use the API to return data from the Chagrin Falls station in Ohio. I can get the data from the website so I know there is data, but the API does not return any values.
I have a valid token and the examples in the documentation work, but if I try any to alter the examples in any way I get nothing back just any empty json object {}.
Example I am trying to use:
https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GSOM&stationid=GHCND:US1OHGG0014&units=standard&startdate=2020-08-01&enddate=2020-08-01&limit=1000
Data from the website:
https://www.ncdc.noaa.gov/cdo-web/datasets/GHCND/stations/GHCND:US1OHGG0014/detail
I don't exactly know how you are going to achieve this since you haven't told us what programming language you are using. However, with python I use a module called urllib to extract raw html data from a url that can be seen from the browser using ctrl+u.

Resources