国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python3.x - python連oanda的模擬交易api時現HTTP Error 401: UNAUTHORIZED?

瀏覽:90日期:2022-07-10 17:26:48

問題描述

用python3連oanda的模擬交易api時現HTTP Error 401: UNAUTHORIZED,新手求教:import urllib.parseimport urllib.request

url = ’https://api-fxpractice.oanda....’access_token = ’a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380’account_id = ’cawa11’values = {’accountId’:account_id}headers = {’Authorization’:’Bearer’+access_token}

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

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

報錯:Traceback (most recent call last): File 'C:UserslenovoDesktopbb.py', line 36, in <module>

response = urllib.request.urlopen(req)

File 'C:Python34liburllibrequest.py', line 161, in urlopen

return opener.open(url, data, timeout)

File 'C:Python34liburllibrequest.py', line 469, in open

response = meth(req, response)

File 'C:Python34liburllibrequest.py', line 579, in http_response

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

File 'C:Python34liburllibrequest.py', line 507, in error

return self._call_chain(*args)

File 'C:Python34liburllibrequest.py', line 441, in _call_chain

result = func(*args)

File 'C:Python34liburllibrequest.py', line 587, in http_error_default

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

urllib.error.HTTPError: HTTP Error 401: UNAUTHORIZED

問題解答

回答1:

#Bearer后面少了一個空格headers = {’Authorization’:’Bearer ’+access_token}回答2:

問題已解決,謝謝各位關注:import requestsimport json instruments = ’EUR_USD’account_id = ’cawa11’access_token = ’a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380’params = {’instruments’:instruments,’accountId’:account_id} headers = {’Authorization’:’Bearer ’+access_token}r = requests.get('https://api-fxpractice.oanda.com/v1/prices',headers = headers, params=params) price = r.json()print(price’prices’[’instrument’].replace(’_’,’/’),’:’,round((price’prices’[’ask’]+price’prices’[’bid’])/2,4))輸出:EUR/USD : 1.0905

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 阳城县| 肥乡县| 河曲县| 磐安县| 涞源县| 油尖旺区| 大同县| 洮南市| 大埔县| 海口市| 丰都县| 德惠市| 广德县| 昌江| 韶关市| 灵寿县| 堆龙德庆县| 三亚市| 南澳县| 盐池县| 定西市| 滨海县| 商城县| 秦皇岛市| 绥江县| 五家渠市| 灌云县| 巩义市| 辽阳市| 阿克| 得荣县| 河北区| 墨江| 迁安市| 邢台县| 宁津县| 乐山市| 大丰市| 天峻县| 龙山县| 郁南县|