Does Robinhood still support its API. I keep getting a login failed error. Here's what I tried:
import requests
def login():
u = "myusername"
p = "mypassword"
url = "https://api.robinhood.com/api-token-auth/"
data = {"username": u, "password": p}
r = requests.post(url, json=data)
return r.text
print login()
I also unsuccessfully tried most of the "Python API Wrappers" on Github.
Give this a try:
import requests
def login():
username = 'username'
password = 'password'
header = {"Accept": "application/json"}
data = {"client_id": "c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS",
"expires_in": 86400,
"grant_type": "password",
"password": "pword",
"scope": "internal",
"username": "uname"}
url = "https://api.robinhood.com/oauth2/token/"
r = requests.post(url, data=data, headers=header)
return r.text
print(login())
Related
I am trying to call an API using an access token.
Currently I am getting the token like so:
import requests
auth_url = "https://oauth.thegivenurl.com/connect/token"
client_id = "SomeClient_ID"
client_secret = "SomeClient_Secret"
scope = "SomeScope"
grant_type = "client_credentials"
data = {
"grant_type": grant_type,
"client_id": client_id,
"client_secret": client_secret,
"scope": scope
}
auth_response = requests.post(auth_url, data=data)
print(auth_response.content)
This produces something like the following:
{"access_token":"eyJhbGdiOihSUzh1NhIsImtpZCI6IjlVUHVwYnBkTXN2RDZ0Ry1ZcDVRUlEiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE2MzM4OTcxNDIsImV4cCI6hTYzMhkwMDc0MiwiaXNzIjoiaHR0cHM6Ly9vYXV0aC56YW1iaW9uLmNvbSIsImF1ZCI6ImFwaTEiLCJjbGllbnRfaWQiOiIwN0I3RkZEOC1GMDJCLTRERDAtODY2OS0zRURBNzUyRTMyNkQiLCJzY29wZSI6WyJhcGkxIl19.GU6lynvQYAAmycEPKbLgHE-Ck189x-a-rVz6QojkBIVpSLu_sSAX2I19-GlTjVWeLKoMVxqEfVq_qIaaQYa5KFmMLHRxP6J-RUgGK8f_APKjX2VNoMyGyAbZ0qXAJCvUTh4CPaRbZ6pexEishzr4-w3JN-hJLiv3-QH2y_JZ_V_KoAyu8ANupIog-Hdg8coI3wyh86OeOSAWJA1AdkK5kcuwC890n60YVOWqmUiAwPRQrTGh2mnflho2O3EZGkHiRPsiJgjowheD9_Wi6AZO0kplHiJHvbuq1PV6lwDddoSdAIKkDscB0AF53sYlgJlugVbtU0gdbXjdyBZvUjWBgw","expires_in":3600,"token_type":"Bearer","scope":"api1"}
Now I would like to call the API and pass the token in a header, but I am unsure how to do this and I have had a couple of goes at online resources
One of my attempts were:
url = "https://anotherurl.com/api/SecuredApi/StaffDetails"
head = {'Authorization': 'token {}'.format(auth_response)}
response = requests.get(url, headers=head)
print(response)
but this gives me a 403 error
Please assist me with pointing out my error
EDIT:
Thanks to #RaniSharim I have made some changes. I now have
import requests
import json
auth_url = "https://oauth.thegivenurl.com/connect/token"
client_id = "SomeClient_ID"
client_secret = "SomeClient_Secret"
scope = "SomeScope"
grant_type = "client_credentials"
data = {
"grant_type": grant_type,
"client_id": client_id,
"client_secret": client_secret,
"scope": scope
}
dateparams = {
"StartDateTime": "2021-01-01 00:00:00",
"EndDateTime" : "2021-10-11 23:59:00"
}
auth_response = requests.post(auth_url, data=data)
# print(auth_response.content)
authjson = auth_response.content
authdata = json.loads(authjson)
token = (authdata['access_token'])
# print(token)
head = {"Authorization": "Bearer " + token}
response = requests.get(url, headers=head, params=dateparams)
print(response.content)
This looks better but I am now getting a 400 error:
"message":"The date range you have specified is in an invalid format. The required format is yyyy-MM-dd HH:mm:ss","status":400}
As best I can see my date ranges are already in the requested format, as set here:
dateparams = {
"StartDateTime": "2021-01-01 00:00:00",
"EndDateTime" : "2021-10-11 23:59:00"
}
Normally, 400 means front-end error, but when you do GET request
dateparams = {
"StartDateTime": "2021-01-01 00:00:00",
}
r = requests.get(url, params=dateparams)
print(r.url)
GET url will turn into sth like this:
https://oauth.thegivenurl.com/connect/token?StartDateTime=2021-01-01+00%3A00%3A00
see the str
2021-01-01+00%3A00%3A00
So if back-end can't handle this right, you'll get this error too
but you can use GET in another way:
requests.get(url, json=dateparams)
This will send your json params perfectly
I want to access Snov.io API but there is Error Unauthenticated. but I authenticated. and I can print Acces token too. am I missing anything here?
import requests
import json
def get_access_token():
params = {
'grant_type': 'client_credentials',
'client_id': '59e814b92ded8ed6b5537718495bf2a5',
'client_secret': '9cc7012893ff220c6935440b8e216ac1'
}
res = requests.post(
'https://api.snov.io/v1/oauth/access_token', data=params)
resText = res.text.encode('ascii', 'ignore')
return json.loads(resText)['access_token']
def user_lists(token):
params = {'access_token': token}
res = requests.get(
'https://api.snov.io/v1/get-user-campaigns', data=params)
return json.loads(res.text)
token = get_access_token()
resp = user_lists(token)
print(token)
print(resp)
get_access_token() is working fine . that's what I am assuming because it's return CODE 200 and access_toke also.
user_lists() return error
ERROR
<Response [401]>
When I try to access Salesforce Analytics REST API using python, it returns following JSON response:
[
{
"message": "This feature is not currently enabled for this user.",
"errorCode": "FUNCTIONALITY_NOT_ENABLED"
}
]
Here's the python code:
access_token = ''
instance_url = ''
def authentication():
global access_token
global instance_url
params = {
"grant_type": "password",
"client_id": "<My Consumer Key>",
"client_secret": "<My Consumer Secret>",
"username": "<My Username>",
"password": "<My Password>"
}
r = requests.post("https://login.salesforce.com/services/oauth2/token", params=params)
print(json.dumps(json.loads(r.text), indent=4))
access_token = r.json().get("access_token")
instance_url = r.json().get("instance_url")
def wave_service():
headers = {
'Authorization': 'Bearer %s' % access_token
}
r = requests.get(instance_url+"/services/data/v49.0/wave", headers=headers)
print(json.dumps(json.loads(r.text), indent=4))
Is there any possible way to enable this wave functionality?
POSTURL = 'https://partner.spreadshirt.de/login'
REQURL = 'https://partner.spreadshirt.de/dashboard'
payload = {
"username": 'test#gmail.com',
"password": 'somepassword'
}
import requests
with requests.Session() as session:
post = session.post(POSTURL, data=payload)
r = session.get(REQURL)
print("String" in r.text)
I know that this String is in present on the Website so this is not the problem. But my code returns False, so maybe I cant get to the REQURL? How could I determine if I got there?
I am trying to send a message via Firebase to a certain client. This is my current (test) code:
import json
import requests
import urllib
def send_message():
server = "https://fcm.googleapis.com/fcm/send"
api_key = "xxx"
user_token = "xxx"
headers = {'Content-Type': 'application/json', 'Authorization': 'key=' + api_key}
data = {"type": "dataUpdate"}
payload = {"data": data, "to": user_token}
payload = json.dumps(payload)
res = requests.post(server, headers=headers, json=payload)
return res
which produces the following error, returned by Firebase:
JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.
The following JSON sent to Firebase seems correct to me:
{
"data": {
"type":"dataUpdate"
},
"to":"xxx"
}
which is in the format described by the Firebase documentation. Any idea why Firebase doesn't accept the given data?
When you use json=payload as a parameter to requests.post() you don't need to specify 'Content-Type': 'application/json' in the header. In addition, you are passing a string when the parameter should be payload as a dict (ie. no need for json.dumps())
Try this:
def send_message():
server = "https://fcm.googleapis.com/fcm/send"
api_key = "xxx"
user_token = "xxx"
headers = {'Authorization': 'key=' + api_key}
data = {"type": "dataUpdate"}
payload = {"data": data, "to": user_token}
res = requests.post(server, headers=headers, json=payload)
return res