Forum in maintenance, we will back soon 🙂
Need Support- flask gives me 404 not found
Hello there Hasan, how are you doing? Hope you are fine! I´m a student of Build and Sell APIs - Establish a New Income Stream. I´m facing an issue in lesson "Build Your First API", particularly in Build With AI ..the browser can not access the API. And the following message is shown to me "Not Found I have no ideia how to figure out what is happening ..
This is the code I have saved in app.py from flask import Flask, request, jsonify import requests app = Flask(__name__) YOUTUBE_SUGGESTION_URL = "http://suggestqueries.google.com/complete/search" @app.route('/youtube-suggestions', methods=['GET']) def youtube_suggestions(): query = request.args.get('query') if not query: return jsonify({"error": "Query parameter is required"}), 400 params = { 'client': 'youtube', 'ds': 'yt', 'q': query, } try: response = requests.get(YOUTUBE_SUGGESTION_URL, params=params) response.raise_for_status() # YouTube returns the suggestions in a JSONP format, we need to strip the padding suggestions = response.text suggestions = suggestions[suggestions.index('(') + 1:suggestions.rindex(')')] suggestions_json = suggestions.strip() suggestions_list = eval(suggestions_json)[1] return jsonify({"suggestions": suggestions_list}) except requests.RequestException as e: return jsonify({"error": str(e)}), 500 if __name__ == '__main__': app.run(debug=True)
|
https://127.0.0.1:5000/youtube-suggestions?query=YOURSEARCH
Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack