rest

How to connect to REST api with a api key

How do I use Riot Games API with an API key? Question: I was trying to connect to the Riot Games API with the Python requests module, and it keeps giving me a 401 error. I added an API key, but it still says unauthorized. If anyone knows what is wrong with the code it …

Total answers: 2

Multiples def, same method in one view

Merge multiple views with same functionality in one view Question: I’m trying to define 4 GET endpoints (max,min,sum,avg) to access by REST. I did this but making 4 views, and I want to know if I can define the 4 methods in a single view. I can’t specify through the url which GET to hit. …

Total answers: 1

Python GET Rest API – package is downloaded but I cannot open it (invalid)

Python GET Rest API – package is downloaded but I cannot open it (invalid) Question: I must run python to get some artifacts from repository in following syntax (invoked from batch with its variables) so this part to pass arguments is not changeable. python get_artifacts.py %USERNAME%:%PASSWORD% http://url/artifactory/package.zip My python script is the following: import sys …

Total answers: 2

Python -Rest API to fetch the bearer – Requests module

Python -Rest API to fetch the bearer – Requests module Question: I have an API, where I need to get the bearer token. When I use ‘Postman’ application, I get the bearer token correctly. I have written below python code for the same but I get below errors. Please help. I need to send username …

Total answers: 1

Appending value to a list depending on the JSON response

Appending value to a list depending on the JSON response Question: I’m calling an API and I get the following response: "items": [ { "packagingType": "PCS", "description": "[REDACTED]", "productCode": "MATT", "freightClass": "300", "insuranceValue": 428.70999999971326, "primaryReferenceNumber": null, "poNumber": "[REDACTED]", "skuNumber": "[REDACTED]", "pluNumber": null, "actualQuantity": 1, "actualWeight": 125, "actualWeightUnitOfMeasure": "Pounds", "actualPallets": 1, "actualVolume": null, "actualVolumeUnitOfMeasure": "Cubic Feet", …

Total answers: 2

FastAPI – Unable to get auth token from middleware's Request object

FastAPI – Unable to get auth token from middleware's Request object Question: Following Starlette documentation (FastAPI uses Starlette for middlewares), response.headers["Authorization"] should allow me to get the bearer token, but I get a KeyError saying no such attribute exists. When I print response.headers, I get MutableHeaders({‘content-length’: ’14’, ‘content-type’: ‘application/json’}). Why is the authorization attribute not …

Total answers: 1

How to allow CORS from Axios get request in Django backend?

How to allow CORS from Axios get request in Django backend? Question: I’ve been looking for a solution to this problem but nothing seems to work. I’ve arrived at the django-cors-headers package but can’t get it to work. I’m sending an axios request form my vue frontend: axios.get(‘data/’) .then(res => { console.log(res) }) but it …

Total answers: 1

AttributeError: 'Flask' object has no attribute 'get

AttributeError: 'Flask' object has no attribute 'get Question: I’m getting the following error while running the below code File "D:Inteliji ProjectsPython Flaskwhatsgrouprestapisrcapp.py", line 13, in create_app @app.get("/") AttributeError: ‘Flask’ object has no attribute ‘get from flask import Flask def create_app(test_config=None): app = Flask(__name__, instance_relative_config=True) if test_config is None: app.config.from_mapping( SECRET_KEY="dev" ) else: app.config.from_mapping(test_config) @app.get("/") def …

Total answers: 1

How to put a dictionary in a JSON?

How to put a dictionary in a JSON? Question: I’m working with a REST API, and I need to return a JSON with my values ​​to it. However, I need the items of the payload variable to show all the items inside the cart_item. I have this: payload = { "items": [], } I tried …

Total answers: 2

How do I push to a nested array in a PyMongo database?

How do I push to a nested array in a PyMongo database? Question: I have a MongoDB database with the following structure (simplified for the question’s sake): User: "id": int "aquarium": Aquarium[] Aquarium: "name": str "fish": Fish[] I have access to: The database, which contains a list of objects of type User, which in turn …

Total answers: 2