Python Requests Equivalent To Curl -h
I'm trying to subscribe to an event stream coming from my particle photon. The docs suggest curl -H 'Authorization: Bearer {ACCESS_TOKEN_GOES_HERE}' \ https://api.particle.io/v1/
Solution 1:
Custom headers are passed as a dictionary in headers
argument
address3 ='https://api.particle.io/v1/events/motion-detected'data = {'Authorization': 'Bearer {ACCESS_TOKEN_GOES_HERE}'}
r3 = requests.get(address3, headers=data)
params
argument is used to pass URL parameters. Basically your code issues a request to https://api.particle.io/v1/events/motion-detected?access_token=token_goes_here
, this can be veriefied by printing url print(r3.url)
Solution 2:
As stated in Alik's response, custom headers are passed as a dictionary in the headers
argument. In your case, that would be
address3 ='https://api.particle.io/v1/events/motion-detected'data = {'Authorization': 'Bearer ' + access_token}
r3 = requests.get(address3, headers=data)
Since this is authentication, the cleanest way would be to implement a custom authentication handler that set this header as described in the documentation.
Post a Comment for "Python Requests Equivalent To Curl -h"