julien-c HF staff commited on
Commit
136ae30
1 Parent(s): e5cbaf1

hook httpx

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,9 +1,15 @@
 
 
 
1
  from starlette.applications import Starlette
2
  from starlette.exceptions import HTTPException
3
  from starlette.responses import FileResponse, JSONResponse, HTMLResponse
4
  from starlette.requests import Request
5
  from starlette.routing import Route
6
 
 
 
 
7
 
8
  async def homepage(_):
9
  return FileResponse("static/index.html")
@@ -17,12 +23,18 @@ async def convert(req: Request):
17
  url = req.query_params.get("url")
18
  if not url:
19
  raise HTTPException(400, "Param url is missing")
20
- print(url)
 
 
 
 
 
 
21
  return HTMLResponse("<strong>FOO</strong>")
22
 
23
 
24
  app = Starlette(
25
- debug=True,
26
  routes=[
27
  Route("/", homepage),
28
  Route("/healthz", healthz),
 
1
+ import os
2
+ import httpx
3
+ from nbconvert import HTMLExporter
4
  from starlette.applications import Starlette
5
  from starlette.exceptions import HTTPException
6
  from starlette.responses import FileResponse, JSONResponse, HTMLResponse
7
  from starlette.requests import Request
8
  from starlette.routing import Route
9
 
10
+ client = httpx.AsyncClient()
11
+ html_exporter = HTMLExporter(template_name="classic")
12
+
13
 
14
  async def homepage(_):
15
  return FileResponse("static/index.html")
 
23
  url = req.query_params.get("url")
24
  if not url:
25
  raise HTTPException(400, "Param url is missing")
26
+ r = await client.get(
27
+ url,
28
+ headers={"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"},
29
+ follow_redirects=True,
30
+ # httpx no follow redirect by default
31
+ )
32
+ print(r.text)
33
  return HTMLResponse("<strong>FOO</strong>")
34
 
35
 
36
  app = Starlette(
37
+ debug=False,
38
  routes=[
39
  Route("/", homepage),
40
  Route("/healthz", healthz),
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  starlette==0.23.1
2
  nbconvert==7.2.8
3
  uvicorn==0.20.0
 
1
+ httpx==0.23.3
2
  starlette==0.23.1
3
  nbconvert==7.2.8
4
  uvicorn==0.20.0