خرید بک لینک

Vote count: 0

I've started a flask app with python. I'm using yelp-python https://github.com/Yelp/yelp-python to access to yelp api

from yelp.client import Client
from yelp.oauth1_authenticator import Oauth1Authenticator
from IPython import embed

auth = Oauth1Authenticator(
  consumer_key='key',
  consumer_secret='secret',
  token='token',
  token_secret='secret'
)

client = Client(auth)

app = Flask(__name__)

@app.route('/hello')
def hello_world():
  response = client.search('pizza hut')
  embed()
  retu jsonify(response)

if __name__ == '__main__':
  app.run(debug=True,host='0.0.0.0')

response is <yelp.obj.search_response.SearchResponse object at 0x7fab7fc80c50> and jsonify says that it can't serialize it.

How do I serialize it so that I can send back json?

I can parse response.businesses which gives me a list but even that jsonify doesn't seem to accept.

Here's an example of some manual parsing:

In [1]: response
Out[1]: <yelp.obj.search_response.SearchResponse at 0x7faa0806d940>

In [2]: response.businesses
Out[2]: 
[<yelp.obj.business.Business at 0x7faa0809a1d0>,
 <yelp.obj.business.Business at 0x7faa0809a208>,
 <yelp.obj.business.Business at 0x7faa0809a278>,
 <yelp.obj.business.Business at 0x7faa0809a320>,
 <yelp.obj.business.Business at 0x7faa0809a3c8>,
 <yelp.obj.business.Business at 0x7faa0809a470>,
 <yelp.obj.business.Business at 0x7faa0809a518>,
 <yelp.obj.business.Business at 0x7faa0809a5c0>,
 <yelp.obj.business.Business at 0x7faa0809a668>,
 <yelp.obj.business.Business at 0x7faa0809a710>,
 <yelp.obj.business.Business at 0x7faa0809a7b8>,
 <yelp.obj.business.Business at 0x7faa0809a860>,
 <yelp.obj.business.Business at 0x7faa0809a908>,
 <yelp.obj.business.Business at 0x7faa0809a9b0>,
 <yelp.obj.business.Business at 0x7faa0809aa58>,
 <yelp.obj.business.Business at 0x7faa0809ab00>,
 <yelp.obj.business.Business at 0x7faa0809aba8>,
 <yelp.obj.business.Business at 0x7faa0809ac50>,
 <yelp.obj.business.Business at 0x7faa0809acf8>,
 <yelp.obj.business.Business at 0x7faa0809ada0>]

In [3]: response.businesses[0]
Out[3]: <yelp.obj.business.Business at 0x7faa0809a1d0>

In [4]: response.businesses[0].name
Out[4]: 'Franco Manca'

I guess I can manually setup a list of dictionaries. I guess it would just be nice if I could parse < object at > into a json object. If anyone could explain < object at > and how to deal with it I'd appreciate it. Thanks

asked 4 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 14 ارديبهشت 1395 ساعت: 8:43

صفحه بندی