I've got a problem with using requests in python to upload files.
non-working code:
import requests
url = 'https://discord.com/api/v9/channels/XXXXX/messages'
headers = {
'authorization': 'XXXXX'
}
data = {
'file': open('test.png', 'rb')
}
r = requests.post(url=url, headers=headers, data=data)
print(r)
print(r.text)
This is the response I get:
<Response [400]>
{"message": "Cannot send an empty message", "code": 50006}
so I tried adding to data "content": "Whoas"
data = {
'file': open('test.png', 'rb'),
"content": "Whoas"
}
Which will now at least send the message, but without the file.
Here's the response I get:
<Response [200]>
{"id": "XXXXX", "type": 0, "content": "Whoas", "channel_id": "XXXXX", "author": {"id": "XXXXX", "username": "XXXXX", "avatar": "XXXXX", "discriminator": "2885", "public_flags": 0}, "attachments": [], "embeds": [], "mentions": [], "mention_roles": [], "pinned": false, "mention_everyone": false, "tts": false, "timestamp": "2021-05-22T09:08:47.061000+00:00", "edited_timestamp": null, "flags": 0, "components": [], "referenced_message": null}
I'm most likely just not understanding the discord API documentation (https://discord.com/developers/docs/resources/channel#create-message), which unfortunately doesn't go into detail about how to upload a file.
I've tried using the module discord.py with discord.File('test.png') but this method isn't giving back the link to the uploaded file, which I need.
If anyone has any idea how to get this to work, it would be really appreciated!
From what I can tell here... you’re using API calls to operate a bot. In reality, this is a very complex process which is why we have libraries such as discord.py to make everything simpler. If you’re looking to create a bot, you should totally check out their documentation.
Related
I have a logic app with started when there is a message in serviceBus queue. The message is being published to the service bus from the DevOps pipeline using "PublishToAzureServiceBus" as a JSON message or from the pipeline webhook.
But getting an issue while converting a message from service bus to original JSON format, not able to get valid JSON object. It's getting append with some Serialization object.
I have tried with base64 decode, and JSON converts but have not been able to get success.
Below is the content of the message it looks like.
Any pointer on how can solve this?
Sample message sent
{
"id": "76a187f3-c154-4e60-b8bc-c0b754e54191",
"eventType": "build.complete",
"publisherId": "tfs",
"message": {
"text": "Build 20220605.8 succeeded"
},
"detailedMessage": {
"text": "Build 20220605.8 succeeded"
},
"resource": {
"uri": "vstfs:///Build/Build/288",
"id": 288,
"buildNumber": "20220605.8",
"url": "https://dev.azure.com/*******/_apis/build/Builds/288",
"startTime": "2022-06-05T14:47:01.1846966Z",
"finishTime": "2022-06-05T14:47:16.7602096Z",
"reason": "manual",
"status": "succeeded",
"drop": {},
"log": {},
"sourceGetVersion": "LG:refs/heads/main:********",
"lastChangedBy": {
"displayName": "Microsoft.VisualStudio.Services.TFS",
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "***************"
},
"retainIndefinitely": false,
"definition": {
"definitionType": "xaml",
"id": 20,
"name": "getReleaseFile",
"url": "https://dev.azure.com/************/_apis/build/Definitions/20"
},
"requests": [
{
"id": 288,
"url": "https://dev.azure.com/B*****/**********/_apis/build/Requests/288",
"requestedFor": {
"displayName": "B*****.sag",
"id": "*******",
"uniqueName": "B**********"
}
}
]
},
"resourceVersion": "1.0",
"resourceContainers": {
"collection": {
"id": "*******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"account": {
"id": "******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"project": {
"id": "**********",
"baseUrl": "https://dev.azure.com/B*****/"
}
},
"createdDate": "2022-06-05T14:47:28.6089499Z"
}
Message received
#string3http://schemas.microsoft.com/2003/10/Serialization/�q{"id":"****","eventType":"build.complete","publisherId":"tfs","message":{"text":"Build 20220605.8 succeeded"},"detailedMessage":{"text":"Build 20220605.8 succeeded"},"resource":{"uri":"vstfs:///Build/Build/288","id":288,"buildNumber":"20220605.8","url":"https://dev.azure.com/*****/********/_apis/build/Builds/288","startTime":"2022-06-05T14:47:01.1846966Z","finishTime":"2022-06-05T14:47:16.7602096Z","reason":"manual","status":"succeeded","drop":{},"log":{},"sourceGetVersion":"LG:refs/heads/main:f0b1a1d2bd047454066cf21dc4d4c710bca4e1d7","lastChangedBy":{"displayName":"Microsoft.VisualStudio.Services.TFS","id":"00000000-0000-0000-0000-000000000000","uniqueName":"******"},"retainIndefinitely":false,"definition":{"definitionType":"xaml","id":20,"name":"getReleaseFile","url":"https://dev.azure.com/******/_apis/build/Definitions/20"},"requests":[{"id":288,"url":"https://dev.azure.com/*****/******/_apis/build/Requests/288","requestedFor":{"displayName":"baharul.sag","id":"******","uniqueName":"baharul.*****"}}]},"resourceVersion":"1.0","resourceContainers":{"collection":{"id":"3*****","baseUrl":"https://dev.azure.com/*****/"},"account":{"id":"******","baseUrl":"https://dev.azure.com/*****/"},"project":{"id":"*******","baseUrl":"https://dev.azure.com/*****/"}},"createdDate":"2022-06-05T14:47:28.6089499Z"}
When reading message from service bus in peek mode can see as below where <#string3http://schemas.microsoft.com/2003/10/Serialization/��> is appended to json string
Publish using PublishToAzureServiceBus from Azure pipeline.
Publish from Azure DevOps project webhook
I believe what is happening is that you have two different types of serialisation in the body of the brokered message created by the PublishToAzureServiceBus task. This is because the brokered message only supports binary content.
So the json is initially serialised as a binary string using the data contract serialiser.
How to solve this? Do the following before passing to your json deserialiser - unfortunately the logic app isn't doing this:
byte[] messageContent = brokeredMessage.GetBody<byte[]>();
string messageContentStr = Encoding.UTF8.GetString(messageContent);
I probably wouldn't use a logic app to do the reading of the message because to insert c# like I suggest you're gonna need to call an azure function or similar. I'd create an azure function to read your messages as above.
I am currently using axios with the Vimeo API.
I'm confused on why I can request https://api.vimeo.com/tags/customtag and get a response showing that there is indeed 35 videos.
"metadata": {
"connections": {
"videos": {
"uri": "/tags/customtag/videos",
"options": [
"GET"
],
"total": 35
}
}
},
But then if I make another request using the uri in the previous request like https://api.vimeo.com/tags/customtag/videos it is empty:
{
"total": 0,
"page": 1,
"per_page": 25,
"paging": {
"next": null,
"previous": null,
"first": "/tags/customtag/videos?page=1",
"last": "/tags/customtag/videos?page=1"
},
"data": []
}
These videos are indeed hidden off of Vimeo for competitor confidentiality purposes. Is there a way to access this data and keep it private?
EDITED:
This is a bug on the Response, the tags do not return private videos.
You can fetch your private videos using your videos endpoint,
https://developer.vimeo.com/api/reference/videos#get_videos
You can use the filter_tag query parameter, so for example
GET /me/videos?filter_tag=customtag should do what you're looking for.
I am trying to create a report using the Coinbase API. I am pulling the request body from the documentation's generated curl. I am getting an error in the response.
request:
const result = await sendRequest('/reports', 'POST', {
"start_date": "2016-01-0100:00:00.000Z",
"end_date": new Date().toISOString(),
"type": "account",
"format": "csv",
"account_id": "ALL",
"product_id": "ALL"
});
response snip:
"status":400,"statusText":"Bad Request","body":{"message":"invalid report type"}
Regardless of what I set the type to in the body, I get this same error.
I am making an API Call to Docusign to try to get a link for a recipient to sign his document without him having to go into his e-mail. I am doing this in APEX in a Visualforce page.
I am sending the following request to the endpoint: "https://demo.docusign.net/restapi/v2/accounts/661863/envelopes/21F02F6C-E156-46E0-BCDE-778D18DB4592/views/recipient"
My Request is:
{
"authenticationMethod": "email",
"email": "test#outlook.com",
"returnUrl": "www.docusign.net",
"userName": "LB -1 Demo 2"
}
The response I am getting is:
{
"errorCode": "UNKNOWN_ENVELOPE_RECIPIENT",
"message": "The recipient you have identified is not a valid recipient of the specified envelope. Envelope recipient could not be determined. 'clientUserId', 'email', or 'userName' in request and envelope may not match."
}
The envelope request is:
{
"signers": [
{
"name": "LB -1 Demo 2",
"email": "test#outlook.com",
"recipientId": "1",
"requireIdLookup": "false",
"userId": "05b324da-8ebb-4d4b-a58b-0ef019530214",
"routingOrder": "1",
"roleName": "Signer 1",
"status": "completed",
"signedDateTime": "2014-06-24T11:30:09.4630000Z",
"deliveredDateTime": "2014-06-24T11:29:58.5100000Z"
}
],
"agents": [],
"editors": [],
"intermediaries": [],
"carbonCopies": [],
"certifiedDeliveries": [],
"inPersonSigners": [],
"recipientCount": "1",
"currentRoutingOrder": "1"
}
The recipient information seems to match my request but the API call is still not working. Is this because I am missing a clientUserId and that is required for am embedded signing call? And if so, would I need to create the Envelope AND Recipients AND ONLY THEN can I make the embedded signer call?
This question is a duplicate, please search the DocuSignApi tag for existing answers before posting new questions. As Andrew has mentioned, this is a duplicate of this question:
Docusign Embedded Signing
You need to set the clientUserId property for any recipient who you want to be an embedded recipient. It's up to you what value to use, but make sure you include the same exact value when requesting the signing URL token.
There's also a detailed explanation of this on the DocuSign Developer Center under Features -> Embedding
https://www.docusign.com/developer-center/explore/features/embedding-docusign
I just started to work with Kinvey and I'm having some issues to POST data via REST api.
If I go in the datastore I'm able to save it, but it doesn't work when sending via POST.
To post data, I'm using the URL "/appdata/APP_KEY/DATASTORE/" and sending Authorization, X-Kinvey-API-Version and Content-Typein the Headers.
And I get back "An unknown internal error occured in the processing of the Business Logic code."
When I add my business logic with App Engine (for a while, it just returns status=200 to Kinvey), I have the same error:
{
"error": "BLInternalError",
"description": "The Business Logic script did not complete. See debug message for details.",
"debug": "An unknown internal error occured in the processing of the Business Logic code."
}
Does anyone have any idea where am I doing wrong?
For the last, even when I call Kinvey via GET the method that Kinvey calls App Engine is POST, is there a way to change it?
Despite the errors, I always have the log of access in Google App Engine.
Thank you!
I sent an email to Kinvey support and they helped me a lot.
Some of my mistakes:
The JSON that I was returning back was wrong [*];
I didn't add in the header of my response the Content-Type and status.
Now it works perfectly!
[*] The JSON that I send back in the body of the response is:
{
"request": {
"method": "<redacted>",
"username": "<redacted>",
"entityId": "<redacted>",
"collectionName": "<redacted>",
"headers": {
"connection": "<redacted>",
"host": "<redacted>",
"x-forwarded-for": "<redacted>",
"x-forwarded-port": "<redacted>",
"x-kinvey-api-version": "<redacted>",
"x-real-ip": "<redacted>",
"authorization": "<redacted>",
"x-forwarded-proto": "<redacted>"
},
"body": "<redacted>",
"params": "<redacted>"
},
"response": {
"complete": True,
"headers": {
"x-powered-by": "<redacted>",
"x-kinvey-api-version": "<redacted>",
"x-kinvey-request-id": "<redacted>"
},
"body": {},
"error": None,
"statusCode": 200
}
}
Thanks again to Brian in the Kinvey support!
[]'s