Skip to content

Instantly share code, notes, and snippets.

@riceissa
Created February 8, 2023 08:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riceissa/9e327d3de3f49624b2d60086d237af32 to your computer and use it in GitHub Desktop.
Save riceissa/9e327d3de3f49624b2d60086d237af32 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
query = """
{
posts(input: {
terms: {
view: "top"
limit: 50
meta: null
}
}) {
results {
_id
title
}
}
}
"""
# request made without setting a user agent; defaults to 'python-requests/2.28.1'
r1 = requests.get("https://www.lesswrong.com/graphql", params={'query': query})
# request made using a typical browser's user agent
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0"
r2 = requests.get("https://www.lesswrong.com/graphql", params={'query': query}, headers={'User-Agent': user_agent})
print(r1.status_code) # prints 403
print(r2.status_code) # prints 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment