flask
アプリをpython
で開始しました。私はYelpのAPIにアクセスするためにyelp-python
https://github.com/Yelp/yelp-pythonを使用していPythonこれは<object at 0x7fab7fc80c50>とは何を意味し、どのように解析できますか?
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()
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')
応答が<yelp.obj.search_response.SearchResponse object at 0x7fab7fc80c50>
あるとjsonify
はそれをシリアル化することができないと言います。
json
を返信できるようにシリアル化するにはどうすればよいですか?
を解析すると、私にはlist
が与えられますが、それでもjsonifyは受け入れられないようです。
はここにいくつかの手動解析の例です:
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'
私は手動でセットアップdictionaries
のlist
ことができますね。私は<オブジェクトをjsonオブジェクトにパースすることができればいいと思う。誰もが< object at >
を説明することができ、それに対処する方法を私はそれを感謝したい。ありがとう