Skip to content

Forum in maintenance, we will back soon 🙂

Need Support- flask...
 
Notifications
Clear all

Need Support- flask gives me 404 not found

3 Posts
2 Users
5 Reactions
76 Views
(@bruno-andre-corsini-melani-catelan)
Posts: 2
Active Member Customer Registered
Topic starter
 

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
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again." Then I get this return on VS Code "127.0.0.1 - - [16/Jul/2024 21:10:32] "GET / HTTP/1.1" 404 -"

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)

 

 

 
Posted : 07/18/2024 4:00 am
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

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

 
Posted : 07/18/2024 12:42 pm
(@bruno-andre-corsini-melani-catelan)
Posts: 2
Active Member Customer Registered
Topic starter
 

@ssadvisor Thank you very much friend. it works!  😀

 
Posted : 07/19/2024 3:34 am
Share: