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

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

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

瀏覽:256日期: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久久,三上悠亚国产精品一区二区三区
久久在线91| 91看片一区| 国产精久久久| 国产真实久久| 亚洲黄页一区| 国产精品久久久久久久久免费高清| 91日韩免费| 91免费精品国偷自产在线在线| japanese国产精品| 亚洲日本免费电影| 国产欧美日韩一级| 乱人伦精品视频在线观看| 国产精品99在线观看| 欧美精品国产一区| 久久免费精品| 亚洲精品激情| 国产伦精品一区二区三区在线播放| 国产在线视频欧美一区| 亚洲天堂久久| 麻豆理论在线观看| 欧美专区在线| 香蕉久久国产| 午夜精品免费| 久久精品国产www456c0m| av亚洲一区二区三区| 久久99性xxx老妇胖精品| 日本不良网站在线观看| 香蕉精品999视频一区二区| 麻豆中文一区二区| 日韩激情综合| 综合日韩在线| 青草国产精品久久久久久| 九九九精品视频| 国产精品免费大片| 中文字幕一区二区三区四区久久| 伊人影院久久| 在线观看亚洲精品福利片| 免费久久99精品国产自在现线| 视频一区二区国产| 久久亚洲精精品中文字幕| 精品亚洲美女网站| 国产亚洲亚洲| 久久国产欧美日韩精品| 91综合网人人| 亚洲欧美久久| 国产日韩欧美三区| 日韩激情一区二区| 精品一区二区三区中文字幕视频 | 国产一区二区三区自拍| 日韩精品电影一区亚洲| 久久久人人人| 老司机精品视频网| 亚洲免费毛片| 欧美福利一区| 麻豆视频在线看| 国产在线观看www| 欧美一级网址| 日本欧洲一区二区| 在线观看一区| 国产欧美激情| 美美哒免费高清在线观看视频一区二区 | 三级久久三级久久久| 欧美国产亚洲精品| 日韩在线视频一区二区三区| 妖精视频成人观看www| 亚洲午夜精品久久久久久app| 久久久精品区| 91av一区| 日韩va亚洲va欧美va久久| 亚洲精品中文字幕99999| 日韩精品一二三四| 中文不卡在线| 日韩精品久久久久久久软件91| 日韩激情一二三区| 三上悠亚国产精品一区二区三区 | 五月天激情综合网| 成年男女免费视频网站不卡| 国产精品一区二区三区av麻| 中文字幕视频精品一区二区三区| 精品视频99| 日韩在线不卡| 欧美日韩高清| 色爱综合网欧美| 日韩av免费大片| 四虎国产精品免费观看| 日韩精品电影一区亚洲| 日韩av自拍| 亚洲精品97| 在线国产一区二区| 超级白嫩亚洲国产第一| 色综合视频一区二区三区日韩 | 国产自产自拍视频在线观看 | 免费国产亚洲视频| 精品国产不卡一区二区| 99精品视频精品精品视频| 国产精品www.| 一级欧美视频| 亚洲一区二区毛片| 国产v综合v| 电影91久久久| 国产精品中文字幕制服诱惑| 亚洲图片久久| 99视频一区| 九九综合九九| 亚洲www免费| 国产a久久精品一区二区三区| 日韩在线卡一卡二| 99精品电影| 日韩.com| 国产日韩欧美一区在线| 亚洲免费毛片| 天堂va在线高清一区| 亚洲免费中文| 99视频在线精品国自产拍免费观看| 蜜臀国产一区| 黄色在线一区| 日韩午夜免费| 国产午夜久久| 一区久久精品| 日韩亚洲精品在线| 9色国产精品| 免费成人av在线播放| 亚洲综合不卡| 亚洲香蕉久久| 一区二区国产在线| 蜜桃av一区二区| 亚洲欧美日韩视频二区| 玖玖玖国产精品| 伊人久久亚洲| 日韩三级精品| 国产精品毛片aⅴ一区二区三区| 国产麻豆一区二区三区 | 精品视频97| 精品入口麻豆88视频| 精品国产一级| 韩国精品主播一区二区在线观看| 98精品视频| 久久精品高清| 三级欧美韩日大片在线看| 亚洲91在线| 国产精品视频一区二区三区 | 免费视频一区二区| 香蕉久久一区| 久久不见久久见中文字幕免费| 国产精成人品2018| 中国字幕a在线看韩国电影| 丝袜av一区| 黄色不卡一区| 日日夜夜免费精品视频| 清纯唯美亚洲综合一区| 欧美激情99| 成人自拍av| 日韩一区精品视频| 国产亚洲精品美女久久| 高清一区二区三区av| 国产精品99一区二区| 丝袜美腿亚洲一区| 国产欧美日韩一区二区三区四区 | 一区二区三区四区日韩| 欧美久久亚洲| 成人影视亚洲图片在线| 亚洲精品国产偷自在线观看| 免费在线成人网| 麻豆视频久久| 久久视频精品| 日本一区二区三区视频在线看| 精品国产亚洲一区二区三区大结局| 久久九九电影| 午夜精品影视国产一区在线麻豆| 国产精品videossex久久发布 | 中文字幕日本一区二区| 牛牛精品成人免费视频| 国产精品久久久久av电视剧| 噜噜噜躁狠狠躁狠狠精品视频| 国产伦精品一区二区三区千人斩| 国产精品精品| 一区二区三区四区在线观看国产日韩| 欧美极品一区二区三区| 欧美精品二区| 中文精品视频| 精品国产一区二区三区性色av| 亚洲成人二区| 日本成人一区二区| 久久激情中文| 国产精品中文| 狠狠干成人综合网| 久久精品国产999大香线蕉| 日韩视频二区| 国产福利资源一区| 欧美午夜不卡影院在线观看完整版免费| 欧美综合精品| 不卡一区2区| 欧美激情视频一区二区三区免费 | av在线资源| 最新国产精品视频| 日韩天堂在线| 国产精品网址| 免费一区二区视频| 91精品综合| 久久超级碰碰|