Reputation: 21
I have this error when I am trying to get response after the call of the API I want to use.
ValueError: [TypeError("'property' object is not iterable"),
TypeError('vars() argument must have __dict__ attribute')]
I am trying to use fastapi in order get from the client the latitudes and longitudes so i could show the public trasnportation of that area. I could do this with an API called GeoApify. However, I have a problem and I can not find my error.
I make a request by using a dictionary in order to put all the parameters for my filter and then I convert the response to JSON. But i have this error.
from pickletools import string1
from fastapi import FastAPI
import requests
from requests.structures import CaseInsensitiveDict
app = FastAPI()
@app.get("/thanos/{lon}/{lat}")
async def read_item(lat : float,lon : float):
url = "https://api.geoapify.com/v2/places"
headers = CaseInsensitiveDict()
dict = {
"categories" : 'public_transport',
"filter" : 'circle:' + str(lon) + ',' + str(lat) + ",500",
"limit" : '20',
"apiKey" : '086a77f34e3a4ed583da9606318ca0ac'
}
params = dict
headers = CaseInsensitiveDict(params)
headers["Accept"] = "application/json"
resp = requests.get(url, headers = headers)
# resp = requests.get(url = url, params = params)
data = resp.json
return resp
Upvotes: 2
Views: 7856
Reputation: 34129
Use as below:
from fastapi import FastAPI
import requests
from requests.structures import CaseInsensitiveDict
import urllib
app = FastAPI()
url = "https://api.geoapify.com/v2/places"
@app.get("/{lon}/{lat}")
def read_item(lat : float, lon : float):
params = {
"categories" : 'public_transport',
"filter" : 'circle:' + str(lon) + ',' + str(lat) + ",500",
"limit" : '20',
"apiKey" : '086a77f34e3a4ed583da9606318ca0ac'
}
headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
params = urllib.parse.urlencode(params)
resp = requests.get(url=url, params=params, headers=headers)
return resp.json()
Upvotes: 2