![]() |
Receiving Werkzeug. exception. Bad Request error when using GET with an endpoint - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Receiving Werkzeug. exception. Bad Request error when using GET with an endpoint (/thread-19502.html) |
Receiving Werkzeug. exception. Bad Request error when using GET with an endpoint - robogeek - Jul-02-2019 Hello, I was trying to implement an API using Python, and flask to help myself learn and practice REST. The idea was to receive a HTTP POST with data that looks like as such: {"startDate":"2015-07-01","endDate":2015-07-08","within":{"value":9000,"units":miles}} I was able to create a POST method , and I am able to receive the data (both in POSTMAN and in the browser). Here is the relevant code : @neows.route('/UserInput',methods=['GET','POST']) def UserInput(): startDate = request.args.get('startDate') endDate = request.args.get('endDate') #print (type(startDate)) #print (type(endDate)) getAsteroids(startDate,endDate) return jsonify(request.args)But when I use the data provided above to GET some data from a NASA API I am receiving this error: werkzeug.exceptions.BadRequestKeyError Here is the url I am trying to hit : Nasa Endpoint I am able to hit the url both on POSTMAN and browser, outside of my code. Here is the relevant piece of code def getAsteroids(startDate,endDate): API_KEY='8Yrp7t6VDsh5DahF7i1hzLEykr9IHljF8LrZ70RL' print (startDate) print (endDate) [color=#C0392B]result=request.args["https://api.nasa.gov/neo/rest/v1/feed? start_date="+startDate+"&end_date="+endDate+"&api_key="+API_KEY+""][/color]The line above in red is throwing the error. I would really appreciate if someone could help me understand and resolve the issue. Thank you |