tecladocode / rest-apis-flask-python Goto Github PK
View Code? Open in Web Editor NEWProjects and e-book for our course, REST APIs with Flask and Python
Home Page: https://rest-apis-flask.teclado.com
Projects and e-book for our course, REST APIs with Flask and Python
Home Page: https://rest-apis-flask.teclado.com
Running the app on render.com triggers the following
OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: stores
[SQL: SELECT stores.id AS stores_id, stores.name AS stores_name
FROM stores]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Seems like the data.db is not created when running the app
When testing in Digital Ocean it showed a 500 error when I tried to create a new item with store id 1 without creating a store before sending the request.
Maybe it would be nice to check the existence of a store and show a more informative message.
Also, add to the course a note about this happening.
Library flask_jwt is outdated. (Last commit was 3 years ago)
The guide is located here.
After it is installed, we can create a virtualenv:
virtualenv venv --python==python3.5
From looking at the virtualenv documentation, I believe it should be a single equals sign in the command.
virtualenv venv --python=python3.5
This is a great guide, thank you!
Hi,
In section 6 of your course, you spoke about circular dependency, but I don't understand why.
I try to put 'from db import db' at the top of the app.py file and it work without errors.
Could you explain brieffly, in which case this circular dependency happen ?
thanks,
Mickael
in chapter 4 authentication and logging part2:
I got error when sending GET /auth
<!doctype html>
<html lang=en>
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
in addition nginx in showed msg in the broswer 404 Not Found
i still google to fix them........and please if you add tut how to use MySQL instead of PostgreSQL but also you can help..thanks in advance sir Jose
*** Starting uWSGI 2.0.16 (64bit) on [Thu Feb 22 11:39:09 2018] ***
compiled with version: 5.4.0 20160609 on 22 February 2018 09:17:09
os: Linux-4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018
nodename: Flask-Api-Test
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /
detected binary path: /var/www/html/items-rest/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
dropping root privileges as early as possible
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your processes number limit is 3913
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/html/items-rest/socket.sock fd 3
dropping root privileges after socket binding
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
Set PythonHome to /var/www/html/items-rest/venv
Python main interpreter initialized at 0x2066f80
dropping root privileges after plugin initialization
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1315008 bytes (1284 KB) for 64 cores
*** Operational MODE: preforking+threaded ***
added /var/www/html/items-rest/ to pythonpath.
rest-apis-flask-python/section6/resources/item.py
Lines 48 to 60 in 3380640
Hi,
In Lec99, the HTTP response of PUT is not fully correctly dealt with. According to this: https://httpwg.org/specs/rfc7231.html, PUT should return 201, when new resource has been created.
(Also, added error handling similarly to the post() method)
So, I think implementation of put() should be appended with the HTTP response code handling, like this:
def put(self, name):
data = Item.parser.parse_args()
item = ItemModel.find_by_name(name)
# if item with name doesn't exist, we create it
if item is None:
item = ItemModel(name, **data)
http_status_code = 200
else:
item.price = data["price"]
http_status_code = 201
try:
item.save_to_db()
except:
return {"message": "An error occurred upserting the item."}, 500
return item.json(), http_status_code
Best,
Csb
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.