questrade_api icon indicating copy to clipboard operation
questrade_api copied to clipboard

Seem cannot make connection now

Open yardern opened this issue 11 months ago • 7 comments

Thank you very much for developing this software!

I am using the fork by @kerouac01850. When trying to connect, I got: "Failed to authenticate using Questrade token ..."

But the same token worked when I used Chrome to browse: https://login.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token=x....x I got proper response, not "Bad Request".

Hope this can be fixed.

yardern avatar Jan 30 '25 00:01 yardern

See https://www.reddit.com/r/Questrade/comments/1hf2zmn/comment/m2j8cm4/

kerouac018502 avatar Jan 30 '25 01:01 kerouac018502

For me I found the user-agent was blocked. I updated these:

questrade_api/auth.py: r =
urlopen(Request(self.config['Auth']['RefreshURL'].format(token),
headers={'User-Agent': 'Mozilla'}))
questrade_api/questrade.py: return urllib.request.Request(url,
headers={'User-Agent': 'Mozilla'})
questrade_api/questrade.py: return
urllib.request.Request(self.__base_url + url, headers={'User-Agent':
'Mozilla'})
questrade_api/questrade.py: return urllib.request.Request(url,
data=json.dumps(params).encode('utf8'), headers={'User-Agent':
'Mozilla'})

On Wed, 2025-01-29 at 16:32 -0800, yardern wrote:

Thank you very much for developing this software! I am using the fork by @kerouac01850 [1]. When trying to connect, I got: "Failed to authenticate using Questrade token ..." But the same token worked when I used Chrome to browse: https://login.questrade.com/oauth2/token?grant_type=refresh_token&refresh_token=x....x I got proper response, not "Bad Request". Hope this can be fixed. — Reply to this email directly, view it on GitHub [2], or unsubscribe [3]. You are receiving this because you are subscribed to this thread.Message ID: @.***>

[1] @kerouac01850 https://github.com/kerouac01850 [2] view it on GitHub https://github.com/tgardiner/questrade_api/issues/16 [3] unsubscribe https://github.com/notifications/unsubscribe-auth/AADFH77CXEGMXON76N6UJ432NFXJ3AVCNFSM6AAAAABWEC2R22VHI2DSMVQWIX3LMV43ASLTON2WKOZSHAYTSNRTGYZDKNI

mgostick avatar Jan 30 '25 01:01 mgostick

See https://www.reddit.com/r/Questrade/comments/1hf2zmn/comment/m2j8cm4/

@kerouac018502 Thank you! I have sent e-mail to Questrade, hope them will answer me.

yardern avatar Jan 31 '25 00:01 yardern

For me I found the user-agent was blocked. I updated these:

questrade_api/auth.py:
r = urlopen(Request(self.config['Auth']['RefreshURL'].format(token), headers={'User-Agent': 'Mozilla'}))

@mgostick Thank you!

I followed your solution, but for questrade_api/auth.py, yours is not accepted, so I changed it to: r = request.urlopen(self.config['Auth']['RefreshURL'].format(token),headers={'User-Agent': 'Mozilla'})

But sadly it didn't work.

yardern avatar Jan 31 '25 00:01 yardern

My full diff of auth.py4c4< from urllib import request---> from urllib.request import urlopen, Request37c37,38<         r = request.urlopen(self.config['Auth']['RefreshURL'].format(token))--->         r = urlopen(Request(self.config['Auth']['RefreshURL'].format(token), headers={'User-Agent': 'Mozilla'}))On Jan 30, 2025, at 7:52 PM, yardern @.***> wrote:

For me I found the user-agent was blocked. I updated these: questrade_api/auth.py: r = urlopen(Request(self.config['Auth']['RefreshURL'].format(token), headers={'User-Agent': 'Mozilla'}))

@mgostick Thank you! I followed your solution, but for questrade_api/auth.py, yours is not accepted, so I changed it to: r = request.urlopen(self.config['Auth']['RefreshURL'].format(token),headers={'User-Agent': 'Mozilla'}) But sadly it didn't work.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

mgostick avatar Jan 31 '25 01:01 mgostick

@mgostick

Very appreciated for your quick response. My knowledge of python is very limited, without your help I would not be able to figure it out by myself.

I changed the import in questrade_api/auth.py to: from urllib.request import urlopen, Request

Together with the 3 mods to questrade_api/questrade.py you provided before, somehow it is still not connecting. The script would abort with "Bad Request" at: r = urlopen(Request(self.config['Auth']['RefreshURL'].format(token), headers={'User-Agent': 'Mozilla'}))

I don't know how frequent I can request the connection, but right after that I tried with Chrome, and got proper responses. If I try more it will fail.

yardern avatar Jan 31 '25 03:01 yardern

Changed the related section of questrade_api/auth.py to:

    req = urllib.request.Request(self.config['Auth']['RefreshURL'].format(token), headers={"User-Agent": "Mozilla/5.0"})
    with urllib.request.urlopen(req) as response:
        if response.getcode() == 200:
              ......

Made it working!

Thanks and Cheers!

yardern avatar Feb 01 '25 23:02 yardern