cari

Rumah  >  Soal Jawab  >  teks badan

python3.x - Ralat HTTP 401: TIDAK DIBENARKAN muncul apabila python menyambung ke api dagangan simulasi oanda?

用python3连oanda的模拟交易api时现 Ralat HTTP 401: TIDAK DIBENARKAN,新手求教:
import urllib.parse
import urllib.request

url = 'https://api-fxpractice.oanda....'
access_token = 'a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380'
='account count_id}
headers = {'Kebenaran': 'Pembawa'+token_akses}

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

req = urllib.request.Request(url, data, header)

respons = urllib.request.urlopen(req)
the_page = response.read()

报错:

Traceback (panggilan terbaharu terakhir):
Fail "C:UserslenovoDesktopbb.py", baris 36, dalam <modul>

response = urllib.request.urlopen(req)

Fail "C:Python34liburllibrequest.py", baris 161, dalam urlopen

return opener.open(url, data, timeout)

Fail "C:Python34liburllibrequest.py", baris 469, dalam keadaan terbuka

response = meth(req, response)

Fail "C:Python34liburllibrequest.py", baris 579, dalam http_response

'http', request, response, code, msg, hdrs)

Fail "C:Python34liburllibrequest.py", baris 507, dalam kesilapan

return self._call_chain(*args)

Fail "C:Python34liburllibrequest.py", baris 441, dalam _call_chain

result = func(*args)

Fail "C:Python34liburllibrequest.py", baris 587, dalam http_error_default

raise HTTPError(req.full_url, code, msg, hdrs, fp)

urllib.error.HTTPERror: Ralat HTTP 401: TANPA KEBENARAN

漂亮男人漂亮男人2776 hari yang lalu863

membalas semua(2)saya akan balas

  • 某草草

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

    #Bearer后面少了一个空格
    headers = {'Authorization':'Bearer '+access_token}
    

    balas
    0
  • PHP中文网

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

    Masalah telah selesai, terima kasih atas perhatian anda:
    permintaan import
    import json
    instruments = 'EUR_USD'
    account_id = 'cawa11'
    access_token = 'a554db3a48ac81865a69794a655a697456a 34f4ce 05e4380'
    params = {'instrumen':instrumen, 'accountId':account_id }
    headers = {'Authorization':'Bearer '+access_token}
    r = requests.get("https://api-fxpractice.oanda.com/v1/prices",headers = header, params =params)
    harga = r.json()
    cetak(harga'harga'['instrumen'].ganti('_','/'),':',bulat((harga'harga'['tanya' ]+harga'harga '['bid'])/2,4))
    Output: EUR/USD: 1.0905

    balas
    0
  • Batalbalas