日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

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

python3.x - python連oanda的模擬交易api獲取json問題第五問

瀏覽:258日期:2022-06-30 10:59:45

問題描述

在正常工作1個多小時后有時突然停止工作沒有任何報錯,或者報錯requests.packages.urllib3.exceptions.ProtocolError: (’Connection aborted.’, BadStatusLine('’’',)),網上其他地方有的說是超時、有的說是說連的是https、有的說要換成python3.5或以上(我用的是python3.4)

程序就是原來上幾問中的程序再加個while True :的循環,謝謝

程序:

import requestsimport jsonurl = 'https://api-fxpractice.oanda.com/v1/prices'instruments = ’EUR_USD,USD_CAD’account_id = ’cawa11’params = {’instruments’:instruments,’accountId’:account_id}access_token = ’a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380’ headers = {’Connection’: ’Keep-Alive’, ’Accept-Encoding’: ’gzip,deflate’, ’Authorization’:’Bearer ’+access_token} #Bearer后有空格while True : r = requests.get(url,headers = headers, params=params) price = r.json() print(r.json()) print(price[’prices’][0][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][0][’ask’]+price[’prices’][0][’bid’])/2,4),’ ’,price[’prices’][0][’time’]) print(price[’prices’][1][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][1][’ask’]+price[’prices’][1][’bid’])/2,4),’ ’,price[’prices’][1][’time’])

報錯信息:

Traceback (most recent call last): File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 554, in urlopen self._prepare_proxy(conn) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 750, in _prepare_proxy conn.connect() File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connection.py', line 230, in connect self._tunnel() File 'C:Python34libhttpclient.py', line 815, in _tunnel (version, code, message) = response._read_status() File 'C:Python34libhttpclient.py', line 321, in _read_status raise BadStatusLine(line)http.client.BadStatusLine: ’’During handling of the above exception, another exception occurred:Traceback (most recent call last): File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsadapters.py', line 376, in send timeout=timeout File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 609, in urlopen _stacktrace=sys.exc_info()[2]) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3utilretry.py', line 247, in increment raise six.reraise(type(error), error, _stacktrace) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3packagessix.py', line 309, in reraise raise value.with_traceback(tb) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 554, in urlopen self._prepare_proxy(conn) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 750, in _prepare_proxy conn.connect() File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connection.py', line 230, in connect self._tunnel() File 'C:Python34libhttpclient.py', line 815, in _tunnel (version, code, message) = response._read_status() File 'C:Python34libhttpclient.py', line 321, in _read_status raise BadStatusLine(line)requests.packages.urllib3.exceptions.ProtocolError: (’Connection aborted.’, BadStatusLine('’’',))During handling of the above exception, another exception occurred:Traceback (most recent call last): File 'C:UserslenovoDesktophh.py', line 27, in <module> r = requests.get(url,headers = headers, params=params) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsapi.py', line 67, in get return request(’get’, url, params=params, **kwargs) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsapi.py', line 53, in request return session.request(method=method, url=url, **kwargs) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestssessions.py', line 468, in request resp = self.send(prep, **send_kwargs) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestssessions.py', line 576, in send r = adapter.send(request, **kwargs) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsadapters.py', line 426, in send raise ConnectionError(err, request=request)requests.exceptions.ConnectionError: (’Connection aborted.’, BadStatusLine('’’',))

按@prolifes說的進行修改后出現的新的報錯信息:Traceback (most recent call last): File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 559, in urlopen

body=body, headers=headers)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 345, in _make_request

self._validate_conn(conn)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 784, in _validate_conn

conn.connect()

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connection.py', line 252, in connect

ssl_version=resolved_ssl_version)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3utilssl_.py', line 305, in ssl_wrap_socket

return context.wrap_socket(sock, server_hostname=server_hostname)

File 'C:Python34libssl.py', line 365, in wrap_socket

_context=self)

File 'C:Python34libssl.py', line 583, in init

self.do_handshake()

File 'C:Python34libssl.py', line 810, in do_handshake

self._sslobj.do_handshake()

TimeoutError: [WinError 10060] 由于連接方在一段時間后沒有正確答復或連接的主機沒有反應,連接嘗試失敗。

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsadapters.py', line 376, in send

timeout=timeout

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 609, in urlopen

_stacktrace=sys.exc_info()[2])

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3utilretry.py', line 247, in increment

raise six.reraise(type(error), error, _stacktrace)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3packagessix.py', line 309, in reraise

raise value.with_traceback(tb)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 559, in urlopen

body=body, headers=headers)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 345, in _make_request

self._validate_conn(conn)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connectionpool.py', line 784, in _validate_conn

conn.connect()

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3connection.py', line 252, in connect

ssl_version=resolved_ssl_version)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestspackagesurllib3utilssl_.py', line 305, in ssl_wrap_socket

return context.wrap_socket(sock, server_hostname=server_hostname)

File 'C:Python34libssl.py', line 365, in wrap_socket

_context=self)

File 'C:Python34libssl.py', line 583, in init

self.do_handshake()

File 'C:Python34libssl.py', line 810, in do_handshake

self._sslobj.do_handshake()

requests.packages.urllib3.exceptions.ProtocolError: (’Connection aborted.’, TimeoutError(10060, ’由于連接方在一段時間后沒有正確答復或連接的主機沒有反應,連接嘗試失敗。’, None, 10060, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 'C:UserslenovoDesktopii.py', line 30, in run

r = requests.get(url,headers = headers, params=params)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsapi.py', line 67, in get

return request(’get’, url, params=params, **kwargs)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsapi.py', line 53, in request

return session.request(method=method, url=url, **kwargs)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestssessions.py', line 468, in request

resp = self.send(prep, **send_kwargs)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestssessions.py', line 576, in send

r = adapter.send(request, **kwargs)

File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsadapters.py', line 426, in send

raise ConnectionError(err, request=request)

requests.exceptions.ConnectionError: (’Connection aborted.’, TimeoutError(10060, ’由于連接方在一段時間后沒有正確答復或連接的主機沒有反應,連接嘗試失敗。’, None, 10060, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File 'C:UserslenovoDesktopii.py', line 133, in <module>

run()

File 'C:UserslenovoDesktopii.py', line 128, in run

print(traceback.format_exc())

NameError: name ’traceback’ is not defined

問題解答

回答1:

把關鍵代碼封裝成函數,并加上錯誤處理,保證while true不中斷,同時打印信息去排查

# coding: utf-8import requestsimport jsonimport tracebackdef run(): try:url = 'https://api-fxpractice.oanda.com/v1/prices'instruments = ’EUR_USD,USD_CAD’account_id = ’cawa11’params = {’instruments’:instruments,’accountId’:account_id}access_token = ’a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380’ headers = {’Connection’: ’Keep-Alive’, ’Accept-Encoding’: ’gzip,deflate’, ’Authorization’:’Bearer ’+access_token} #Bearer后有空格 r = requests.get(url,headers = headers, params=params) price = r.json()print(r.json())print(price[’prices’][0][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][0][’ask’]+price[’prices’][0][’bid’])/2,4),’ ’,price[’prices’][0][’time’])print(price[’prices’][1][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][1][’ask’]+price[’prices’][1][’bid’])/2,4),’ ’,price[’prices’][1][’time’]) except:print traceback.format_exc()if __name__ == ’__main__’: while True:run()回答2:

在@prolifes的幫助下問題已解決,程序如下:

coding: utf-8

import requestsimport jsonimport traceback

def run():

try: url = 'https://api-fxpractice.oanda.com/v1/prices' instruments = ’EUR_USD,USD_CAD’ account_id = ’cawa11’ params = {’instruments’:instruments,’accountId’:account_id}access_token = ’a554db3a48ac8180a6996a5547ba1663-ac5947e64456cc5842a34f4ce05e4380’ headers = {’Connection’: ’Keep-Alive’, ’Accept-Encoding’: ’gzip,deflate’, ’Authorization’:’Bearer ’+access_token} #Bearer后有空格 r = requests.get(url,headers = headers, params=params,timeout=5) price = r.json() print(r.json()) print(price[’prices’][0][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][0][’ask’]+price[’prices’][0][’bid’])/2,4),’ ’,price[’prices’][0][’time’]) print(price[’prices’][1][’instrument’].replace(’_’,’/’),’:’,round((price[’prices’][1][’ask’]+price[’prices’][1][’bid’])/2,4),’ ’,price[’prices’][1][’time’])except: #print traceback.format_exc() pass

if name == ’__main__’:

while True: run()

標簽: Python 編程
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美日韩一区自拍| 日本精品一区二区三区在线观看视频| 日本中文字幕视频一区| 国产真实久久| 999久久久国产精品| 亚洲特色特黄| 日本一区福利在线| 精品精品99| 亚洲精品日本| 国产色噜噜噜91在线精品| 精品一区二区男人吃奶| 欧美日韩一二三四| 免费看日韩精品| 国产精品啊v在线| 亚洲欧美日本日韩| 69堂精品视频在线播放| 97精品国产福利一区二区三区| 日本一区二区三区视频在线看| 精品国产精品国产偷麻豆 | 亚洲制服少妇| 国产乱码精品一区二区亚洲| 久久亚洲欧美| 你懂的国产精品永久在线| 999国产精品视频| 成人午夜网址| 五月天久久网站| 精品国内亚洲2022精品成人| aa国产精品| 麻豆国产在线| 国产欧美88| 国产精品日韩| 久久激情婷婷| 久久久久亚洲精品中文字幕| 欧美手机在线| 成人黄色av| 日本免费在线视频不卡一不卡二| 免费人成网站在线观看欧美高清| 亚洲高清久久| 精品国产精品国产偷麻豆| 日韩一区精品| 国产女优一区| 91久久黄色| 亚洲精品网址| 亚洲五月婷婷| 日韩av福利| 岛国精品一区| 久久久久九九精品影院| 欧美黄色一区二区| 免费日韩av片| 热久久免费视频| 免费在线视频一区| 久热re这里精品视频在线6| 国产精品久久久久av电视剧| 四虎成人av| 久久国产亚洲| 久久要要av| 欧美91福利在线观看| 欧美日韩国产免费观看视频| 蜜桃国内精品久久久久软件9| 亚洲精品电影| 99亚洲视频| 九九久久国产| 毛片在线网站| 亚洲美女久久精品| 女人av一区| 石原莉奈在线亚洲二区| 欧美一区不卡| 中文字幕人成乱码在线观看| 国产精品日韩久久久| 日韩视频一区| 国产91在线精品| 激情五月色综合国产精品| 蜜桃久久精品一区二区| 久久精品福利| 日韩久久一区二区三区| 欧美日韩国产免费观看视频| 精品国产一区二区三区av片| 午夜欧美精品久久久久久久| 视频一区二区国产| 久久不见久久见免费视频7| 97国产成人高清在线观看| 亚洲激情国产| 国产精品久久国产愉拍| 激情偷拍久久| 国产九九精品| 欧美日韩水蜜桃| 中文字幕在线高清| 99riav1国产精品视频| 国产精品一级| 日韩网站在线| 国产精品久久久久蜜臀| 亚洲精品黄色| 日韩av免费| 国产精品一区二区三区av| 久久国产99| 久久精品资源| 精品三级av在线导航| 亚洲神马久久| 日韩电影免费网站| 日本免费新一区视频| 91精品精品| 国产激情在线播放| 国产麻豆精品| 91精品福利观看| 丝袜美腿亚洲色图| 亚洲成人免费| 久久中文字幕二区| 日韩欧美自拍| 麻豆高清免费国产一区| 日本aⅴ精品一区二区三区| 五月天激情综合网| 99久久夜色精品国产亚洲狼 | 欧美日韩在线观看视频小说| 麻豆国产欧美一区二区三区| 国产精品v亚洲精品v日韩精品| 日韩av中文字幕一区| 麻豆一区二区99久久久久| 在线国产一区| 欧美一区三区| 亚洲免费中文| 免播放器亚洲| 99精品国产一区二区三区| 91视频一区| 国产一区二区精品| 国精品一区二区| 红桃视频国产精品| 亚洲少妇自拍| 综合亚洲自拍| 国产乱码精品一区二区三区亚洲人 | 青草综合视频| 日韩成人精品一区二区| 精品视频在线一区二区在线| 美女视频黄免费的久久| 久久精品亚洲| 神马午夜在线视频| 性欧美69xoxoxoxo| 另类欧美日韩国产在线| 精品视频网站| 久久一级电影| 亚洲精品大片| 四虎成人av| 国产欧美自拍一区| 精品国产一区二区三区av片| 99久久久国产精品美女| 蜜臀久久久久久久| 久久永久免费| 亚洲一区免费| 国产视频一区二| 日韩国产网站| 欧美一级一区| 图片区亚洲欧美小说区| 国产色99精品9i| 99精品视频精品精品视频| 日韩精品一区二区三区中文| 成人一区不卡| 日韩高清在线一区| 蜜桃tv一区二区三区| 国产欧美午夜| 国产亚洲一区在线| 成人精品高清在线视频| 亚洲一区二区网站| 麻豆国产在线| 亚洲免费观看| 国产v日韩v欧美v| 欧美一级二级三级视频| 国产乱码午夜在线视频| 亚洲资源网站| 中文字幕一区二区三区在线视频| 精品视频黄色| 日本不卡在线视频| 九九久久婷婷| 91av亚洲| 欧美丰满日韩| 国产精品www994| 日韩1区2区日韩1区2区| 国产精品网站在线看| 欧美有码在线| 亚洲欧美日韩国产一区| 亚洲精品视频一二三区| 国产一区二区三区黄网站| 久久国产三级精品| 亚洲毛片网站| 日韩国产一区二| 久久亚州av| 欧美永久精品| 国产视频网站一区二区三区| 欧美一区二区三区久久精品| 免费日本视频一区| 日韩中文欧美在线| 美美哒免费高清在线观看视频一区二区 | 久久av在线| 最新亚洲激情| 久久不射网站| 日韩精品一区二区三区av | 中文日韩在线| 91久久视频| 亚洲精品麻豆| 久久伊人久久| 蜜桃av在线播放| 红桃视频国产精品|