endpoints_project3_solution.py
Opened this issue · 2 comments
Test 1 FAILED: Could not make POST Request to web server
("the JSON object must be str, not 'bytes'",)
I am getting this error.
On sending the POST request from postman, it shows the desired result.
I'd like to know the reason for this as well. I would like to run the endpoints_tester3.py file to pass all test.
This is an issue with the URL in line 15 of endpoints_tester3.py and being redirected (301 return code) from Flask.
Line 15 reads:
url = address + "/puppies?name=Fido&description=Playful+Little+Puppy"
Line 15 should read (slash after puppies to prevent redirection):
url = address + "/puppies/?name=Fido&description=Playful+Little+Puppy"
From http://flask.pocoo.org/docs/0.10/quickstart/#url-building
Unique URLs / Redirection Behavior
Flask’s URL rules are based on Werkzeug’s routing module. The idea behind that module is to ensure beautiful and unique URLs based on precedents laid down by Apache and earlier HTTP servers.
Take these two rules:
@app.route('/projects/')
def projects():
return 'The project page'
@app.route('/about')
def about():
return 'The about page'
Though they look rather similar, they differ in their use of the trailing slash in the URL definition. In the first case, the canonical URL for the projects endpoint has a trailing slash. In that sense, it is similar to a folder on a file system. Accessing it without a trailing slash will cause Flask to redirect to the canonical URL with the trailing slash.
In the second case, however, the URL is defined without a trailing slash, rather like the pathname of a file on UNIX-like systems. Accessing the URL with a trailing slash will produce a 404 “Not Found” error.
This behavior allows relative URLs to continue working even if the trailing slash is ommited, consistent with how Apache and other servers work. Also, the URLs will stay unique, which helps search engines avoid indexing the same page twice.