python3.x - Question 7 of getting json from python's simulated trading api with oanda
phpcn_u1582
phpcn_u1582 2017-06-12 09:26:53
0
1
1038

Because we are currently using a simulated account to connect to the api, it is restricted. The account_token of the api can only be used to obtain prices and cannot be used to place orders. Therefore, I hope to log in to the web version of the trading platform through simulation to obtain the funds that can be used to place orders. session_token, but I found that there are two URLs, one is the superficial URL, and the other is the URL for submitting the user name and password. I don’t know which URL should be used. In addition, no matter which URL I use, the error ValueError: Expecting value: line will be reported. 1 column 1 (char 0), this seems to be related to utf-8, please help, thank you
Program:

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())

Error report:

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_u1582
phpcn_u1582

reply all(1)
phpcn_u1582
https://fxgame-webapi.oanda.com/v1/user/login.json?api_key=d39400e6d2f3c11a&password=1122334455&username=cawa11
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template