首頁  >  問答  >  主體

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

因為目前使用的是模擬帳戶連接api,因此受到限制,api的account_token只能用於獲取價格,不能用於下訂單,所以我希望透過模擬登入網頁版交易平台,取得可用於下訂單的session_token,但發現有兩個url,一個是表面上的url,另一個是提交使用者名稱和密碼的url,我不知道應該用那個url,另外無論我用哪一個url,都會報錯ValueError: Expecting value: line 1 column 1 (char 0),這好像是和utf-8有關,請大家幫忙,謝謝
程序:

import requests
import json

url = "https://trade.oanda.com/" 
          #另一个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())

報錯:

Traceback (most recent call last):
  File "C:\Users\lenovo\Desktop\oo.py", line 15, in <module>
    print(r.json())
  File "C:\Python34\lib\site-packages\requests-2.9.1-py3.4.egg\requests\models.py", line 808, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Python34\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
phpcn_u1582phpcn_u15822707 天前996

全部回覆(1)我來回復

  • phpcn_u1582

    phpcn_u15822017-06-12 09:28:53

    雷雷

    回覆
    0
  • 取消回覆