Skip to content

Barchart login no longer returns CSRF token #39

Closed

Description

@anannnchim

Barchart’s login page returns HTTP 200, but create_bc_session() cannot find the expected hidden CSRF token.

Original error:

AttributeError: 'NoneType' object has no attribute 'attrs'

After adding validation:

BCException: Barchart login page returned no CSRF token:
status=200, url=https://www.barchart.com/login

Using do_login=False also fails because no XSRF-TOKEN cookie is created.

Are you experiencing the same issue? Has Barchart changed its login flow, and is there a known fix?

Activity

  1. algo0749 commented on Aug 31, 2026

    @algo0749

    I have a feeling that barchart has protected itself from bots getting data for free. It has been protected against bots with cloudflare or another protection system.

    I have been trying all weekend to see what was happening, and it seems that it detects that it is not a real browser and does not send the cookie with the necessary token.

    I personally have not found the solution.

  2. bug-or-feature commented on Aug 31, 2026

    @bug-or-feature
    Owner

    @anannnchim thanks for flagging this, I didn't notice. It does look like something has changed at Barchart. I'll look into it but it may take a while as I'm not using this currently and my premier subscription has expired

  3. bug-or-feature commented on Sep 5, 2026

    @bug-or-feature
    Owner

    I have re-implemented this using a real browser with playwright. See the PR. Initial testing looks good. If anyone can help me with testing it would be appreciated. Post any issues or comments on the PR

  4. anannnchim commented on Sep 14, 2026

    @anannnchim
    Author

    I tested PR #40 successfully. The browser launched correctly, Barchart login completed without the previous CSRF/XSRF-token error, and a single-contract download produced a valid CSV containing Time, Open, High, Low, Close, and Volume data. Persisted authentication also worked as expected.
    From my testing, PR #40 resolves the login issue reported here. Thank you for implementing the browser-based flow.

  5. bug-or-feature commented on Sep 14, 2026

    @bug-or-feature
    Owner

    @anannnchim thanks. I've been testing too, all good. I'll merge the PR shortly, and do a new release

  6. bug-or-feature commented on Sep 14, 2026

    @bug-or-feature
    Owner

    fixed by #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions