Explanation :
When i print new_movie_data it gives Unicode Error.
Error : UnicodeEncodeError: 'charmap' codec can't encode characters in position 4167-4177: character maps to <undefined>
My CODE :
@app.route("/add", methods=["GET", "POST"])
def add():
add_form = FindMovieForm()
if add_form.validate_on_submit():
movie_title = add_form.add_movie.data
response = requests.get(f"{MOVIE_DB_SEARCH}{api_key}&query={movie_title}")
new_movie_data = response.json()["results"]
redirect(url_for("home"))
return render_template("add.html", form=add_form)
i want to print new_movie_data in json so i can parse this data into another template which shows on different page i try different methods of applying UTF-8 into new-movie-data but none of them work.
2
Answers
Thanks bro @hc_dev its working the problem is in my MOVIE_DB_SEARCH url and request i put first api key and then query but in your code query is first and in last is api-key.
HERE is my Movie-DB-search url and response: '
'
Also i didnt put headers in request but it also works without putting headers in request ....
Your request and response seems to be the issue (not Flask).
Since you mentioned "MOVIE_DB_SEARCH" I took this URL and API for my minimal reproducible example:
Probably you have more chance when taking the binary-stream from
response.content
.See: python requests.get() returns improperly decoded text instead of UTF-8?
See also
The Movie Database API docs and reference: