Skip to content

How can I use the API with Python requests module? #381

Discussion options

You must be logged in to vote

Reading up on how curl & cookies work I was able to build something that works in Python. Posting here in case someone else is looking for it:

#!/usr/bin/python3
import requests
curSession = requests.Session()

# all cookies received will be stored in the session object
payload={'username': "apiuser",'password': "test"}

resp1 = requests.post("http://127.0.0.1:3000/api/auth/authenticate", data=payload)

# manually pass previously returned cookies into following request
resp2 = requests.get("http://127.0.0.1:3000/api/torrents", cookies=resp1.cookies)
print(resp2.json())

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@CluelessTechnologist
Comment options

@jesec
Comment options

Comment options

You must be logged in to vote
1 reply
@CluelessTechnologist
Comment options

Answer selected by CluelessTechnologist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants