For the last 4 days, my Stack Exchange view count graphing script has been breaking with StackAPI claiming that:

requests.exceptions.InvalidURL: Failed to parse: https://api.stackexchange.com/2.2/sites/

It had been working fine for the last year without any modifications, so I don't think this is a coding mistake on my end. Did Stack Exchange update something in its API output?

You can reproduce the error with this Python code:

from stackapi import StackAPI

Apologies if this should be a Stack Overflow question. Let me know.

  • 3
    Other apps are still functioning. There were some changes and issues within the last 2 days, but things generally remained operational. Without at least the actual URLs you're using, it's hard for us to know what the issue is. For example, just https://api.stackexchange.com/2.2/sites/ works fine.
    – Makyen
    Jun 2 at 18:42
  • Maybe something changed on that site which StackAPI is failing to parse? It fails no matter what stack domain I run it on like from stackapi import StackAPI; StackAPI('meta') Jun 2 at 18:50
  • As you can see in the error message, the problem is with the url api.stackexchange.com/2.2/sites Is there some reference as to what changed on it to break StackApi? Jun 2 at 23:35
  • Looks like it's not on SE side, both the URL and the JSON response are fine. Something inside the data itself breaks your script, you'll have to debug to find what exactly. Jun 3 at 16:41
  • 1
    The only difference I see from version from 2022 is addition of "twitter_account" field for each site Jun 3 at 17:11
  • 2
    What, if any, parameters are being sent with that request? What is the full URL that is sent (including the query string)? Have you tried accessing that URL directly from a browser running on the same machine as the script? What is the full error received back from the server?
    – Makyen
    Jun 3 at 17:35
  • @Makyen Thanks that helped. I had to unlock and manually into the stackapi.py file to get what it was doing, which is when I realized it was the python3 requests library that was breaking, not stackapi or stackexchange. Jun 3 at 18:35
  • @SurpriseDog I'm glad you were able to resolve the issue. Please edit your question such that it's possible for others to get from your question to the solution. You don't say in the question which requests library version you were using. You also explicitly say "For the last 4 days", which strongly implies you were either using the same version of requests you'd previously been using or the then current version (which would have already been the fixed version; 2.31.0 was released 2023-05-22, so well outside that 4 days).
    – Makyen
    Jun 3 at 18:40
  • @Makyen I'm running Mint 20 so it's running an older version of the library. On my other computer, also running mint 20, the requests library is on version 2.22.0 which works fine. My guess is that this computer autoupdated to version 2.26.0 in the last few days. Jun 3 at 18:43

1 Answer 1


It's not Stack Exchange or StackAPI; it's something in the Requests library that was broken. With version 2.26.0, I get a "Failed to parse error" for

 requests.get("https://api.stackexchange.com/2.2/sites/", params={'pagesize': 1000, 'page': 1, 'filter': '!*L1*AY-85YllAr2)'})

which is generated by StackAPI, when running something StackAPI('worldbuilding')

For version 2.22.0 on a different computer that line works fine. So I tried downgrading my Requests library with:

pip3 install --force-reinstall -v "requests==2.22.0"

It also works if I force upgrade it to the latest version:

pip3 install --force-reinstall -v "requests==2.31.0"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .