Comments (6)
I believe your solution is best then for sure. Very simple. I just went into site packages and hardcoded a Firefox user agent to v123.00 and it worked fine for me as well. If it does not get approved, I will use the above.
from schwab-api.
Out on vacation, but I've approved the change. Will try to identify a more robust solution to this type of thing going forward
from schwab-api.
I think the most robust fix is to change the user agent to firefox, which is actually the browser used with playwright and to update the version the one used by playwright.
Hence, when playwright is outdated, the login will fail. Once playwright is updated, the USER_AGENT "constant" will update alongside.
from schwab-api.
I agree with the above comment, but if the website does not want to load correctly in firefox for some reason the below library could be used to get a "popular" user agent each time it is called. This should accomplish the same thing.
https://pypi.org/project/fake-useragent/
from schwab-api.
Yes, that was my first thought. However, this schwab-API currently hardcoded firefox anyways. If anything else entered in SessionManager.browserType, it defaults to webkit, which actually doesn't work with Schwab. At least not on the two machines I tried it on.
Additionally:
- fake-agent is another dependency to manage & update.
- if using github actions (which I am), there are some issues with configuring fake-agent to get it to work as it will not allow to connect to willshouse.com. See developer section: https://pypi.org/project/fake-useragent/
I've made a simple tweak to authenticate.py and tested it. I works now and I am about to create a pull request.
Until this change is approved, I recommend adding the following line to your code right after the api call:
Initialize our schwab instance
api = Schwab()
version = api.browser.version
usr_agent = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:{version}) Gecko/20100101 Firefox/{version}"
api.page = api.browser.new_page(
user_agent = usr_agent,
viewport = { 'width': 1920, 'height': 1080 }
)
from schwab-api.
Not sure if this is still relevant, but I had another workaround for this. This is what I implemented while experimenting with the Playwright async API:
try:
async with self.page.expect_navigation():
await self.page.frame(name=login_frame).press("[placeholder=\"Password\"]", "Enter")
except TimeoutError:
raise Exception("Login was not successful; please check username and password")
# Handles out-of-date user agent
if await self.page.get_by_text("Time to Update Your Browser").is_visible():
async with self.page.expect_navigation():
await self.page.click("button:text(\"Continue\")")
if self.page.url != urls.trade_ticket():
return False
await self.page.wait_for_selector("#_txtSymbol")
If you think something like this would be useful, and sufficiently robust, I can raise a PR once https://github.com/itsjafer/schwab-api/pull/51/files has been merged.
from schwab-api.
Related Issues (20)
- margin account orders hit and miss HOT 11
- quote function change? HOT 4
- Options not working anymore HOT 9
- Error when placing order: This order cannot be accepted. Please ensure logged into correct account for order processing through Charles Schwab or TD Ameritrade HOT 1
- Response 413 error in get_account_info_v2() HOT 3
- `get_account_info_v2` KeyError: costDetail HOT 1
- Unable to login - Timeout error HOT 1
- order confirmation to buy or sell a symbol that's traded before today HOT 1
- Locking My Account HOT 3
- TOTP login failing HOT 1
- Symantec ID not working anymore HOT 16
- Allow session to be cached to disk HOT 6
- totp secret HOT 1
- Welcome to Charles Schwab Developer Club (including migration from TD). HOT 1
- OrderManagementSystem in cancel_order_v2() seems to take value 1 HOT 2
- Shorting? HOT 3
- Login Error: waiting for locator("select#landingPageOptions") HOT 13
- This error "It looks like you are using Playwright Sync API inside the asyncio loop. Please use the Async API instead."
- You want us to enter our Schwab username and password on your website? AYFKM? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schwab-api.