itsjafer / schwab-api

A python library for placing trades on Charles Schwab
MIT License
201 stars 64 forks source link

Error: "request entity too large" #20

Closed WinesProof closed 8 months ago

WinesProof commented 8 months ago

As I mentioned in https://github.com/itsjafer/schwab-api/issues/16#issuecomment-1856355799, I started getting "request entity too large" errors all over the place, but I first noticed it in trade_v2().

While debugging the error in an IPython session (embed() right after a failed post request), I found by accident that re-doing the post request after fiddling with self.headers worked- even if I didn't actually change the keys/values in self.headers, but merely assigned one of them to the same value that it already had! If I instead retried the request in an IPython session without fiddling with self.headers, it repeatedly failed with the "request entity too large" error. Go figure.

Since that didn't make sense, I inspected a few things with that successful request compared to the unsuccessful request prior to my IPython session, and I noticed that the successful one omitted the 'ADRUM_BT1' and 'ADRUM_BTa' cookies. So I added a few lines in the code prior to the post request to delete these cookies, and it worked. I ended up adding this before every request throughout the code since these errors occurred in a variety of places.

I would like to think there's a good explanation and/or better fix for this. Hopefully someone out there has some ideas.

itsjafer commented 8 months ago

Interesting, did you find that deleting that cookie from every request had no negative bearing on the functionality?

If that's the case, I'd be happy to make that change

WinesProof commented 8 months ago

I haven't noticed any negative effects yet. It's up to you, but I'm not compelled to recommend this change in your repo until someone else reports something similar or we better understand why it's happening. I've made quite a few changes while working on various things and may have introduced something that caused this.

itsjafer commented 8 months ago

Got it, if anyone else reports a similar problem, I'd be happy to allow users to pass in whatever cookie overrides they'd like to make requests with

QingqiLei commented 8 months ago

Hi, I have met the same problem. Could you please let me know how to omit the 'ADRUM_BT1' and 'ADRUM_BTa' cookies?

WinesProof commented 8 months ago

Prior to any session request that returns this error, you can add:

self.session.cookies.pop('ADRUM_BT1', None)
self.session.cookies.pop('ADRUM_BTa', None)
itsjafer commented 8 months ago

I've gone ahead and made this default behaviour in v0.3.3