Problem importing FastAPI spec into Postman - postman

Trying to test my FastAPI project in Postman. It automatically generates an OpenAPI spec as a JSON file at http://localhost:8000/openapi.json on my machine. When I try to import this link in Postman, it gets hung up at this screen:
When I press the import button I get no error messages and nothing happens no matter how long I wait. I've verified that the JSON file at that URL is valid by pasting its contents into the "Raw Text" import method, which produces a new Postman collection as soon as I hit the "Import" button.

Related

How to link Django and React URLs to perform actions?

In Django, I have my login URL set to 'api/auth/login'. When given a username and password, it will log that user in. Running 'python manage.py runserver', it will put that URL at 'http://127.0.0.1:8000/api/auth/login'
However, my React project, when running 'yarn start' is at 'http://localhost:3000/' and giving it the extension 'api/auth/login', the url it attempts is 'http://localhost:3000/api/auth/login'.
This does not work, but if I replace the URL extension with 'http://127.0.0.1:8000/api/auth/login', the login works as expected.
How can I have the URLs work with my React app? Or is this not something that necessarily needs to be fixed? I do plan to host this project somewhere and am not yet sure how the URLs will work out..
One option is to set proxy in the package.json.
Second option is to set axois baseURL:
// add in your code before main component definition
// for example in App.js
import axios from "axios";
axios.defaults.baseURL = "http://127.0.0.1:8000";
I'm preferring the second approach. For doing production build it can be easily overwritten with an environment variable.
import axios from "axios";
axios.defaults.baseURL = REACT_APP_SERVER_URL
Remember to set the CORS headers in the Django server (I'm working on tutorial with an example how to do this).
You are hosting react application on another port that's why when you put a request without mentioning host, it gets appended to your current host i.e. 127.0.0.1:3000. I suggest you write "proxy": '127. 0.0.1:8000' in your package.json (refer https://create-react-app.dev/docs/proxying-api-requests-in-development/) and restart your react server or use full url of django server i.e. 127.0.0.1:8000/

Flask download sometimes not starting in Firefox

I am trying to send a file from Flask to the browser, as it can observed from the code below
response = make_response(send_file(os.path.abspath(app.root_path)+server_path,as_attachment=True))
response.mimetype = mimetype # Chosen between "application/zip" and "application/gz"
return response
I am not using send_file directly because I need to add extra headers to the response.
The issue is that in Chrome this works flawlessly but when I move to Firefox the download, sometimes, just hangs in the download manager without starting or the download starts but the page will not refresh.
What could be the cause of this behavior?
Is that the full code example, or are you doing other things to the response? Are there other extra headers are you adding at some point? And are you saying it works on firefox when you try send_file without wrapping it in a make_response first?
Also, depending on which version of flask you're using, send_file supports adding an argument to the method for mimetype, see the documentation: http://flask.pocoo.org/docs/1.0/api/#flask.send_file so there might not be a reason for you to wrap it with the make_response function.

Can I get the JSON response from a Flask-api that runs locally using URLLIB or REQUETS?

Is there a way to save the response of a flask api that is running locally on my machine?
It may not make a great sense as I have the logic locally and there is no need to get the response again from the local URL..but in my case, I have another webhook which runs locally which means I need to run flask and my webhook locally.
I am looking to get around this..
You can save your response on your machine through using pickle. But it is not recommended, because website can change their content anytime.
import requests
import pickle
resp = requests.get("https://github.com")
with open("test","wb") as fd:
pickle.dump(resp,fd)
with open("test","rb") as fd:
resp_ = pickle.load(fd)
print(resp_.url)

Upload document in postman

Iam facing some challanges by uploading a document in postman. The steps how to upload a document by the body and choosing form-data then you add file and change it to file instead of tekst. This goes fine and when I excute the call it goes through. But when I close the postman call and try to open it again and excuted it gives me 400 error code. When I look into the body and espacially by the form-data it shows that no file is choosing. So postman is not saving the path where the document is located. In this case I have to added everytime when I want to run the request.
The quastion is how do I fix this problem. Postman is not saving the location of the document.
Thanks in advance

api request returns json files and not html/xml browser content

I am sending get httpwebrequests to the facebook graph api and all was working fine till I deployed to production server and now module that expects html/xml response is not working and when tested url in internet explorer, the save file dialog pops up and the file needs to be saved.
Other modules also send requests to the facebook graph but just differ in the form of requests so not sure what is going on here.
Any ideas appreciated
Edit:
Let me try and rephrase this. On my production server the httpwebrequest was not returning the correct result. So to Test it I copied the url http://graph.facebook.com/pepsi which is an example, should return the profile info viewable in the browser. The server has internet explorer v8 and I am not sure why it tries to download the file instead of displaying it in the browser. this is what is happening in my code and when I make a request to a different part of the api, then it works in my app but not in the browser
Your question is not very clear. From what I gather, you want the display the JSON response in a browser. Instead, you are being asked to download a file by the browser.
Well, this is normal behaviour. The response you get from Facebook would most likely have a MIME type of application/json. Most newer web browsers display the text in the browser itself. Some browsers, however don't know how to handle this content type and just ask you to download the file.
You mentioned that your module expects an html/xml response. Try changing this to application/json.
You also said that it works in your app but not in your browser. I don't know what you're making, but generally you wouldn't show raw json to the user in a browser, right?