Skip to content

Commit f456807

Browse files
authored
Fix: 403 Unauthorized Access (#8498)
Added Authorization header for http requests. Example now can run as-is.
1 parent 3fa1aba commit f456807

File tree

1 file changed

+8
-2
lines changed
  • docs/docs/tutorials/llms_txt_generation

1 file changed

+8
-2
lines changed

docs/docs/tutorials/llms_txt_generation/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,18 @@ import requests
113113
import os
114114
from pathlib import Path
115115

116+
os.environ["GITHUB_ACCESS_TOKEN"] = "<your_access_token>"
117+
116118
def get_github_file_tree(repo_url):
117119
"""Get repository file structure from GitHub API."""
118120
# Extract owner/repo from URL
119121
parts = repo_url.rstrip('/').split('/')
120122
owner, repo = parts[-2], parts[-1]
121123

122124
api_url = f"https://api.github.com/repos/{owner}/{repo}/git/trees/main?recursive=1"
123-
response = requests.get(api_url)
125+
response = requests.get(api_url, headers={
126+
"Authorization": f"Bearer {os.environ.get('GITHUB_ACCESS_TOKEN')}"
127+
})
124128

125129
if response.status_code == 200:
126130
tree_data = response.json()
@@ -135,7 +139,9 @@ def get_github_file_content(repo_url, file_path):
135139
owner, repo = parts[-2], parts[-1]
136140

137141
api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{file_path}"
138-
response = requests.get(api_url)
142+
response = requests.get(api_url, headers={
143+
"Authorization": f"Bearer {os.environ.get('GITHUB_ACCESS_TOKEN')}"
144+
})
139145

140146
if response.status_code == 200:
141147
import base64

0 commit comments

Comments
 (0)