How to request data from udemy api?

Viewed 44

I'm trying to get the courses list of data from udemy api.

I get this message: You do not have permission to perform this action.

from bs4 import BeautifulSoup
import requests

client_id = "my client id"
client_secret = "my client secret"

client_id_secret = f"{client_id}:{client_secret}"

headers = {
  "Accept": "application/json, text/plain, */*",
  "Authorization": f"Basic {client_id_secret}",
  "Content-Type": "application/json;charset=utf-8"
}

r = requests.get("https://www.udemy.com/api-2.0/courses/?page=1&page_size=10&search=python",headers=headers)

soup = BeautifulSoup( r.content , 'html.parser')

print(soup)

I'm expecting to get a list of courses and their URL.

1 Answers

You need to provide the Authorization-Header base64-encoded https://www.udemy.com/developers/affiliate/

First you need to convert your string into an byte-like object and then you can use b64encode to encode it.

import base64
s = "Stackoverflow Answer".encode()  # same as b"Stackoverflow Answer"
encoded = base64.b64encode(s)
Related