webull: place_order returns 405 error

Here’s my code,

from webull import webull
wb._access_token = "XX"
print(wb.place_order("NVOS", action="BUY", quant=1))

it throws this error

Traceback (most recent call last):
  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\webull_handler.py", line 16, in <module>
    p = wb.place_order("NVOS", action="BUY", quant=1)
  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\webull\webull.py", line 624, in place_order
    return response.json()
  File "C:\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

is there any fix to this?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 28 (2 by maintainers)

Most upvoted comments

this is the way to update your accesstoken

fh = open('webull_credentials.json', 'r')
credential_data = json.load(fh)
fh.close()

wb._refresh_token = credential_data['refreshToken']
wb._access_token = credential_data['accessToken']
wb._token_expire = credential_data['tokenExpireTime']
wb._uuid = credential_data['uuid']

n_data = wb.refresh_login()

credential_data['refreshToken'] = n_data['refreshToken']
credential_data['accessToken'] = n_data['accessToken']
credential_data['tokenExpireTime'] = n_data['tokenExpireTime']

file = open('webull_credentials.json', 'w')
json.dump(credential_data, file)
file.close()

# important to get the account_id
wb.get_account_id()

oh well, I got it working, I was using the wrong trade token , Now everything is working including placing order,

Thank you for the help. @ICANTFINDAUSERNAMEATALL it meant a lot to me!

https://github.com/tedchou12/webull/wiki/Workaround-for-Login-Method-2

I wrote a quick summary of the new workaround. lmk if anything is confusing.

Don’t do any of this:

wb._did = "XX"
wb._access_token = "XX"

When you run the login function, it will automatically generate the access token for you instead of using an old one. Just set the did and login.

As you said, here is my code,

from webull import webull
from credentials import WEBULL_USERNAME, WEBULL_PASSWORD

wb = webull()

wb._set_did(
    "XX"
)  
wb.login(WEBULL_USERNAME, WEBULL_PASSWORD, "webull api")
wb.get_trade_token("XX")

q = wb.get_account()
print(q)
p = wb.place_order("UNCY", action="BUY", quant=1, orderType="MKT")
print(p)

Session is expiring somehow, here is the error

{'msg': 'Your session has expired, please login again.', 'traceId': 'XX', 'code': 'trade.token.expire', 'data': {'lock': xx, 'retry': -2}, 'success': False}