python3.x - python連oanda的模擬交易api獲取json問題第七問
問題描述
因?yàn)槟壳笆褂玫氖悄M賬戶連接api,因此受到限制,api的account_token只能用于獲取價(jià)格,不能用于下單,所以我希望通過模擬登錄網(wǎng)頁版交易平臺(tái),獲取可用于下單的session_token,但是發(fā)現(xiàn)有兩個(gè)url,一個(gè)是表面上的url,另一個(gè)是提交用戶名和密碼的url,我不知道應(yīng)該用那個(gè)url,另外無論我用哪一個(gè)url,都會(huì)報(bào)錯(cuò)ValueError: Expecting value: line 1 column 1 (char 0),這好像是和utf-8有關(guān),請(qǐng)大家?guī)兔Γx謝程序:
import requestsimport jsonurl = 'https://trade.oanda.com/' #另一個(gè)url:'https://fxgame-webapi.oanda.com/v1/user/login.json'username = ’cawa11’password = ’1122334455’params = {’username’:username,’password’:password}headers = {’Connection’: ’Keep-Alive’, ’Accept-Encoding’: ’gzip,deflate’, ’charset’:’utf-8’, ’User-Agent’:’Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36’}r = requests.get(url,headers = headers, params=params)print(r.json())
報(bào)錯(cuò):
Traceback (most recent call last): File 'C:UserslenovoDesktopoo.py', line 15, in <module> print(r.json()) File 'C:Python34libsite-packagesrequests-2.9.1-py3.4.eggrequestsmodels.py', line 808, in json return complexjson.loads(self.text, **kwargs) File 'C:Python34libjson__init__.py', line 318, in loads return _default_decoder.decode(s) File 'C:Python34libjsondecoder.py', line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File 'C:Python34libjsondecoder.py', line 361, in raw_decode raise ValueError(errmsg('Expecting value', s, err.value)) from NoneValueError: Expecting value: line 1 column 1 (char 0)
問題解答
回答1:https://fxgame-webapi.oanda.com/v1/user/login.json?api_key=d39400e6d2f3c11a&password=1122334455&username=cawa11
相關(guān)文章:
1. phpadmin的數(shù)據(jù)庫,可以設(shè)置自動(dòng)變化時(shí)間的變量嗎?就是不需要接收時(shí)間數(shù)據(jù),自動(dòng)變化2. html5和Flash對(duì)抗是什么情況?3. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?4. html - 爬蟲時(shí)出現(xiàn)“DNS lookup failed”,打開網(wǎng)頁卻沒問題,這是什么情況?5. javascript - vue項(xiàng)目里的package.json6. ios - 為什么用WKWebView加載相同的html文本,有時(shí)展示的內(nèi)容卻不一樣。7. angular.js - vue中類似于angular的ng-change的指令是?8. mac里的docker如何命令行開啟呢?9. boot2docker無法啟動(dòng)10. 這是什么情況???
