GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — KnowledgeBase/test_upload_with_token.py at master · tailorgunjan93/KnowledgeBase

Expand file tree

/

test_upload_with_token.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
44 lines (37 loc) · 1.61 KB
/

test_upload_with_token.py

Copy path

File metadata and controls

44 lines (37 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncio
import httpx
async def main():
async with httpx.AsyncClient(base_url="http://127.0.0.1:8000", timeout=30.0) as ac:
# 1. Login
login_resp = await ac.post("/auth/login", json={"username": "admin", "password": "password"})
if login_resp.status_code != 200:
# Let's try register if admin doesn't exist
login_resp = await ac.post("/auth/register", json={"username": "admin", "password": "password"})
if login_resp.status_code != 200:
print("Login/Register failed:", login_resp.text)
return
token = login_resp.json()["token"]
headers = {"Authorization": f"Bearer {token}"}
# 2. Get KB list
kb_resp = await ac.get("/api/kb", headers=headers)
if kb_resp.status_code != 200:
print("KB list failed:", kb_resp.text)
return
kbs = kb_resp.json()["items"]
if not kbs:
# Create a KB
create_resp = await ac.post("/api/kb", json={"name": "Test KB", "description": "Test"}, headers=headers)
kb = create_resp.json()
else:
kb = kbs[0]
kb_id = kb["id"]
print(f"Using KB: {kb_id}")
# 3. Upload document
upload_resp = await ac.post(
f"/api/kb/{kb_id}/documents",
files={"file": ("test.txt", b"Hello knowledge base. This is a test document.", "text/plain")},
headers=headers
)
print("Upload Response:", upload_resp.status_code, upload_resp.text)
if __name__ == "__main__":
asyncio.run(main())
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.