mirror of
https://github.com/imputnet/cobalt.git
synced 2026-05-22 14:24:23 -05:00
Error in accessing the cobalt API using Python #82
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @archie-was-taken on GitHub (Jun 23, 2023).
I want to use the API. For starters, I wrote a Python script that would download a YouTube video, e.g. https://www.youtube.com/watch?v=dQw4w9WgXcQ. However, I can't seem to get it. I provided the URL to the API using POST as application/json (as is there in the documentation), but it still didn't work.
I wrote a Python script that looks something like this:
I ran this and then at the Python shell, I did:
The response returned an error saying that I hadn't provided a link, when I clearly had. What's the problem here? What did I do wrong?
@nununoisy commented on GitHub (Jun 26, 2023):
There’s no need to URL-encode a link in a JSON payload, so you are unintentionally sending an invalid URL - remove the
urllib.parseline and just directly embed the link.Also, you can simplify the code and send the correct
Content-Typeheader using thejsonkeyword argument onrequests.post:@archie-was-taken commented on GitHub (Jun 27, 2023):
I did that, and it responded with a 400 HTTP status code.
Here's what
app.pylooks like:@hyperdefined commented on GitHub (Jun 27, 2023):
You have to specify these headers.
And then add them to the reponse:
@archie-was-taken commented on GitHub (Jun 27, 2023):
That worked like a charm—thanks! I'm closing the issue.