Curl is the only option for helix api?

Hey! So I’ve for a long time on and off worked with the helix API and such and has always run in to some troubles.

But this time it atleast has some results on my part.

I was wondering why my post request works in postman (DISCLAIMER: IT ONLY WORKED IF I IMPORTED MY REQUEST AS CURL)

But does not work in a simple python post request?

url = “https://api.twitch.tv/helix/clips?broadcaster_id=463674804
headers = {
‘Authorization’: ‘Bearer cfabd4f5t6klmawdzdo98xt2fo512y’,
‘Client-Id’: ‘uo6dggojybjio9l692zknwmi5ej1q2’}
x = requests.post(url, data = headers)
print(“schleem rules”)
print(x.text)

It just gives me
“error”: “Unauthorized”,
“status”: 401,
“message”: “OAuth token is missing”

When I try through browser, when I try through my python code, even when I try to build the post request from scratch in Postman with literally the same info, It still doesn’t work.

But as soon as I imported your curl example into postman with the same credentials, it worked! heureka! But. Now to the hard part.

Can you help me get your request working in any other environment than Curl? That would be awesome!

Regards,
Schleem - Full time streamer, Web analyst
Beginner programmer and full fledged dreamer

Are you trying to make a Clip or get Clips?

Shouldn’t

x = requests.post(url, data = headers)

be

x = requests.post(url, headers)

To do a Python requests POST request with headers?

Generally speaking all libraries use cURL under the hood. So yes cURL is the only option. Just libraries till do a intrepretation and covert to system calls that will be passed to cURL.

That’s a fast answer! Thanks :smiley:

I tried out your suggestion about switching data = headers → headers. Unfortunately to no avail :frowning:

I just followed by w3 Python Requests post Method

And they propose to do data = headers

Regarding your trivia about cURL. I Thank you and really appreciate it :smiley:

Make clips btw :slight_smile:

Well that suggests

x = requests.post(url, data = myobj, headers = {“HTTP_HOST”: “MyVeryOwnHost”})

So you’d go

headers = {
‘Authorization’: ‘Bearer cfabd4f5t6klmawdzdo98xt2fo512y’,
‘Client-Id’: ‘uo6dggojybjio9l692zknwmi5ej1q2’}
myobj = {}
x = requests.post(url, data = myobj, headers = headers)

I know this works for a get request. https://github.com/BarryCarlyon/twitch_misc/blob/main/authentication/app_access_tokens/python/generate.py#L26

1 Like

YOOOOOOOOO. Barry the fullstack service minded experienced guru dwelling monstrosity Carlyon.

That worked it out.

Initially what your reply looked like I thought was just another way to write what I had done. But hell yeah. This was my last piece of puzzle to create an exe-file where I can clip my (and friends) stream with a hotkey :smiley: POG POG

I will leave you as a hall of fame on my channel now Barry!

Hope you have a wonderful day!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.