Right now, I'm making a PATCH request to https://discord.com/api/v9/users/#me.
f'https://discord.com/api/v9/users/#me',
json = {"username": name},
headers = self.headers(self.getCookies(), token, self.config['x-super-properties']),
proxy=self.proxy
This normally works (I have a bunch of other functions using the same layout) but I'm not exactly sure what to use as the JSON.
I'm thinking I need a password slot in the field but I don't have the password and I'm just using the token. This is the response I get when I log it in console:
{"code": 50035, "errors": {"password": {"_errors": [{"code": "PASSWORD_DOES_NOT_MATCH", "message": "Password does not match."}]}}, "message": "Invalid Form Body"}
Related
Edit: Since this question is getting a good amount of views, I'd like to let you all know before you waste hours of your life on the upload endpoint that it currently requires you to manually click confirm in the app. So it doesn't allow you to fully automate uploads. To anyone which this saves time, you're welcome :)
Currently trying to implement the TikTok api into one of my projects. However having a few difficulties with a specific endpoint. Not sure if its an error on my part or on Tiktoks.
Upon making the below request I am recieving an invalid request body error message. I have followed their documentation to the T so unsure why this is happening?
https://developers.tiktok.com/doc/login-kit-user-info-basic
data = {
"access_token": access_token,
"open_id": open_id,
"fields": [
"open_id",
"union_id",
"avatar_url",
"avatar_url_100",
"avatar_url_200",
"avatar_large_url",
"display_name"
]
}
user_info = requests.post("https://open-api.tiktok.com/user/info/", data=data)
print(user_info.json())
{'data': {}, 'error': {'code': 6007055, 'log_id': '', 'message': 'invalid request body'}}
Use json parameter instead of data
import requests
data = {
"access_token": access_token,
"open_id": open_id,
"fields": [
"open_id",
"union_id",
"avatar_url",
"avatar_url_100",
"avatar_url_200",
"avatar_large_url",
"display_name"
]
}
user_info = requests.post("https://open-api.tiktok.com/user/info/", json=data)
print(user_info.json())
I sending my access_token via payload in postman like this, to get information like email, name at my backend.:
{
"access_token": "my-google-acces-token"
}
In backend, i try to send this access_token to a google request like this:
response = requests.get('https://www.googleapis.com/oauth2/v2/userinfo',
headers={'Authorization': f'Bearer {access_token_data}'})
And i get this response:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
what i doing wrong? my google-acess-token is right
I am learning flask Restful API, where I came upon RequestParser
wherein my example includes
data_put = reqparse.RequestParser(bundle_errors=True)
data_put.add_argument("username",type=str,help="Username not provided",location="json",required=True)
data_put.add_argument("new_password",type=str,help="New password not provided", location="json", required=True )
this above code snippet works great with username and new_password parameter and returns error message if any, as
{
"message": {
"username": "Username not provided",
}
}
this is great.
But is it possible to insert a user defined value into the response message,
for example, can I get a response as
{
"message": {
"username": "Username not provided",
"error_code": 1000
}
}
where value of error code will be a variable.
Yeah, you can remove the required from the .add_argument line, and the in the class, where you get the post/get after you do
args = data_put.parseargs()
You can check if there is the username in the args
if args["username"]:
return {"message": "Wrong username"}
And return a HTTP status or error code
I'm creating an application in Azure AD as a daemon to get user phone
authentication methods using the python msal library and calling the following following endpoint GET https://graph.microsoft.com/beta/users/{id | UPN}/authentication/phoneMethods but i get the following error
{
"error": {
"code": "accessDenied",
"message": "Request Authorization failed",
"innerError": {
"message": "Request Authorization failed",
"date": "2020-11-19T19:26:28",
"request-id": "11975e07-ee6b-4bd2-9a74-7c175c5da560",
"client-request-id": "11975e07-ee6b-4bd2-9a74-7c175c5da560"
}
}
}
My app has the required application permissions to get the info i'm looking for, which are UserAuthenticationMethod.Read.All and UserAuthenticationMethod.ReadWrite.All and it already works with different end points such as GET https://graph.microsoft.com/beta/users/{id | UPN}, this is the code i'm using in order to get the access token required and call the graph api
import json
import logging
import requests
import msal
config = {
"authority": "https://login.microsoftonline.com/TENANT_NAME",
"client_id": "APP_ID",
"scope": ["https://graph.microsoft.com/.default"],
"secret": "APP_SECRET",
"endpoint": "https://graph.microsoft.com/beta/users/{USER_ID}/authentication/phoneMethods"
}
app = msal.ConfidentialClientApplication(
config["client_id"], authority=config["authority"],
client_credential=config["secret"],
)
result = None
result = app.acquire_token_silent(config["scope"], account=None)
if not result:
logging.info("No suitable token exists in cache. Let's get a new one from AAD.")
result = app.acquire_token_for_client(scopes=config["scope"])
if "access_token" in result:
graph_data = requests.get(
config["endpoint"],
headers={'Authorization': 'Bearer ' + result['access_token']}, ).json()
print("Graph API call result: ")
print(json.dumps(graph_data, indent=2))
else:
print(result.get("error"))
print(result.get("error_description"))
print(result.get("correlation_id"))
i tried to do the same thing using curl or postman and i get the exact same error, so i'm guessing it's an access token issue maybe ?
Thanks in advance
The api call does not support application permissions. You need to grant delegated permissions to the application, and then use the auth code flow to obtain the token.
When sending a post request to a python CGI server via jquery, sometimes some of the arguments are clipped. When sending the same post request again the request is received in with complete data.
I have checked the chrome browser network requests and they show that request is being fully sent.
Here is an example of a partially sent request:
var message = {
"to": "test.user#gmail.com",
"sender": "test.user#gmail.com",
"code": "K96nhC4qnIvzcM3XzaIMwfwuRjBooyHZWwtM1hIE\n2rD2WuvZ4B3/2J0xfDstsj91B/K8i7V6gjx1l/Mm\nX5skxuy6ih63ChZN3IWZjIXDCZ1F3V15/7oYDlsa\n6rgueyzEuW87nQJAmAh2P7tFEC6SQxEu/rln8DNs\nMrGSQRdMRY2kmzyVlnKbWEuZ6yjJes7TKaQ2GhL7\nSvAP4DMRl1mKSwnA7qAaCHVqG9iCPqyjy2eKJN/C\nviF7kBavfAZqcMlyY76VyMVSg3zG7t1LUfUA"
}
And the same request fully sent:
var message = {
"to": "test.user#gmail.com",
"sender": "test.user#gmail.com",
"code": "K96nhC4qnIvzcM3XzaIMwfwuRjBooyHZWwtM1hIE\n2rD2WuvZ4B3/2J0xfDstsj91B/K8i7V6gjx1l/Mm\nX5skxuy6ih63ChZN3IWZjIXDCZ1F3V15/7oYDlsa\n6rgueyzEuW87nQJAmAh2P7tFEC6SQxEu/rln8DNs\nMrGSQRdMRY2kmzyVlnKbWEuZ6yjJes7TKaQ2GhL7\nSvAP4DMRl1mKSwnA7qAaCHVqG9iCPqyjy2eKJN/C\nviF7kBavfAZqcMlyY76VyMVSg3zG7t1LUfUAhsMN\nXWSoVzG/kmKJen3czBo74UT8s0eUXCtFa01Hfecv\nGbQVBHHlTCrz3y5IoOqUQQDHtzE5oke7TL46nv52\nhwr1Q0/Sc9+QXA+rd/iMOWKjEY+AfbizI5K6v4VJ\nlP6wEL1Wo49f5haAukgJ6kWjx4hI8dcwEKrM5kbR\nDqQ3nQuIAnYM+8NeMmfjgoS4ReovtjQPjN/dk+eP\nEGiF8XWkIHHuerORq/9PERxeitJcZEWWYSkmjPu9\n8mW4K3jSm0SG3LV+E6mOx3uycCYkh9O1mqfwBk+3\nEE8litsIJ84ivZ+FzPZsbI0u9w3zsKE="
}
Both examples are JSON formatted from server logs.
Here is the javascript:
$.post('cgi-bin/somescript.py', message, someCallback, 'text')
Your 'data' should be a stringified Javascript object:
data: JSON.stringify({ "userName": userName, "password" : password })
Or, to send the data from the form, pass it formData, like this:
data: JSON.stringify(formData)
There's also a more detailed answer to a similar question here: Jquery Ajax Posting json to webservice
orginal answer