python3+djangoで、外部のAPIにアクセスするウェブアプリを開発しています。
unirestを使用しようとしましたが、以下のようにエラーが出ています。
ネットで検索すると、あまり情報が無いようなので、python3でunirestを使用するのは、メジャーじゃないのかなと思っています。
python3でunirestが使えるのか?
それについての解説サイトはないのか?
もしくは、
python3で外部APIをたたく時の標準的な方法が他にあるのか?
などアドバイスいただけると助かります。
unirestインストール時のエラー
lang
1$ pip3 install unirest 2Collecting unirest 3 Downloading Unirest-1.1.6.tar.gz 4Collecting poster>=0.8.1 (from unirest) 5 Downloading poster-0.8.1.tar.gz 6 Traceback (most recent call last): 7 File "<string>", line 20, in <module> 8 File "/tmp/pip-build-okpnxb_7/poster/setup.py", line 2, in <module> 9 import poster 10 File "/tmp/pip-build-okpnxb_7/poster/poster/__init__.py", line 29, in <module> 11 import poster.streaminghttp 12 Complete output from command python setup.py egg_info: 13 Traceback (most recent call last): 14 15 File "<string>", line 20, in <module> 16 17 File "/tmp/pip-build-okpnxb_7/poster/setup.py", line 2, in <module> 18 19 import poster 20 21 File "/tmp/pip-build-okpnxb_7/poster/poster/__init__.py", line 29, in <module> 22 23 import poster.streaminghttp 24 25 ---------------------------------------- 26 Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-okpnxb_7/poster 27
想定しているコード
開発中は自サーバー上のテストAPIをたたいています。
lang
1def tweet_test(request): 2 3 API_URL = 'http://localhost:10030/twitterapi' 4 5 query_string = urllib.urlencode({"name":"しまりそ"}) 6 7 response = unirest.get(API_URL + "/twitterapi?" + query_string) 8 9 if response.code != 200: 10 raise Exception("HTTP Error %d in /greeting/hello: %s" % (response.code, response.raw_body)) 11 12 html = response.body 13 14 return HttpResponse(html)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。