ホームページ  >  に質問  >  本文

python3.x - Python が oanda のシミュレートされた取引 API に接続すると、HTTP エラー 401: UNAUTHORIZED が表示されますか?

python3 を使用した oanda の模倣取引 api 時のHTTP エラー 401: UNAUTHORIZED,新しい手求教:
import urllib.parse
import urllib.request

url = 'https://api-fxpractice.oanda....'
access_token = 'a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380'
account_id = 'cawa11'
values = {'accountId':account_id}
headers = {'認可':'ベアラー' アクセストークン}

data = urllib.parse.urlencode(値).encode("utf-8")

req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req)
the_page = response.read()

报错:
トレースバック (最新の呼び出しは最後):
ファイル "C:UserslenovoDesktopbb.py"、36 行目、<module>

リーリー

ファイル「C:Python34liburllibrequest.py」、urlopen の 161 行目

リーリー

ファイル「C:Python34liburllibrequest.py」、469行目、オープン

リーリー

ファイル「C:Python34liburllibrequest.py」、http_response の 579 行目

リーリー

ファイル「C:Python34liburllibrequest.py」、507行目、エラーです

リーリー

ファイル「C:Python34liburllibrequest.py」、行 441、_call_chain

リーリー

ファイル「C:Python34liburllibrequest.py」、587 行目、http_error_default

リーリー

urllib.error.HTTPError: HTTP エラー 401: UNAUTHORIZED

漂亮男人漂亮男人2712日前795

全員に返信(2)返信します

  • 某草草

    某草草2017-05-18 10:58:04

    リーリー

    返事
    0
  • PHP中文网

    PHP中文网2017-05-18 10:58:04

    問題は解決しました。ご清聴ありがとうございました:
    インポートリクエスト
    import json
    instruments = 'EUR_USD'
    account_id = 'cawa11'
    access_token = 'a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc584 2a34f4ce 05e4380'
    params = {'楽器':楽器, 'accountId':account_id }
    headers = {'Authorization':'Bearer '+access_token}
    r =requests.get("https://api-fxpractice.oanda.com/v1/prices",headers = ヘッダー、パラメータ=params)
    price = r.json()
    print(price'prices'['instrument'].replace('_','/'),':',round((price'prices'['ask' ]+price'prices '['bid'])/2,4))
    出力: EUR/USD: 1.0905

    返事
    0
  • キャンセル返事