Giter VIP home page Giter VIP logo

Comments (6)

MaxxRK avatar MaxxRK commented on July 27, 2024 1

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.

itsjafer avatar itsjafer commented on July 27, 2024 1

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.

4rumprom avatar 4rumprom commented on July 27, 2024

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.

MaxxRK avatar MaxxRK commented on July 27, 2024

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.

4rumprom avatar 4rumprom commented on July 27, 2024

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.

tristanpenman avatar tristanpenman commented on July 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.