1

We are trying to execute a Get Request from the Azure Web App using our python code. The request will be made to our DevOps Repo following the available API. This is just a part (example) of the entire code:

from fastapi import FastAPI
import requests
import base64
import uvicorn

app = FastAPI()

@app.get("/")
async def root():
    return {"Hello": "Pycharm"}

@app.get('/file')
async def sqlcode(p: str = '/ppppppppp',
            v: str = 'vvvv',
            r: str = 'rrrrrr',
            pn: str = 'nnnnnnn'):
    organizational_url = f'https://xxxxxxxx/{pn}/_apis/git/repositories/{r}/items?path={p}&versionDescriptor.version={v}&api-version=6.1-preview.1'
    username = 'username'
    password = 'password'
    basic_authentication = base64.b64encode((f'{username}:{password}').encode('utf-8')).decode('utf-8')
    headers = {
        'Authorization': f'Basic {basic_authentication}',
    }
    response = requests.get(url=organizational_url, headers=headers) 
    return {"sqlcode": response.text}


# Code ends for Fastapi with swagger
def print_hi(name):
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

And this is the requirements.txt

Flask==2.0.1
asyncpg==0.21.0
databases==0.4.1
fastapi==0.63.0
gunicorn==20.0.4
pydantic==1.7.3
SQLAlchemy==1.3.22
uvicorn==0.11.5
config==0.3.9
pandas==1.5.3
dask==2023.1.0
azure.storage.blob==12.14.1
pysftp==0.2.9
azure-identity==1.12.0
azure-keyvault-secrets==4.6.0

When we execute the code in Pycharm this works without any issue :

enter image description here

But when we execute the same code from the Web App we've got the Internal Server Error Message

enter image description here

I'm just trying to help the team to understand this error. I'm not a cloud engineer. What could be missing, is it something in the code, a particular port to use, is a permission needed in Azure Web Service?

d2907
  • 798
  • 3
  • 15
  • 45
  • Can you get the application logs from azure? There should be a python error there. – M.O. Jan 26 '23 at 20:55
  • Hi That is the thing. The logs does not show nothing, and unfortunately we do not have manager permission. – d2907 Jan 26 '23 at 20:57
  • 1
    Please have a look at [this answer](https://stackoverflow.com/a/73736138/17865804) and [this answer](https://stackoverflow.com/a/74239367/17865804) on how to issue HTTP requests inside FastAPI `async def` endpoints. – Chris Jan 27 '23 at 14:09

0 Answers0