I've installed Flask-Restless and am trying to run the quickstart app. All requests return a 404 error (both in the python logs and in the curl response). My whole setup is:
$ virtualenv venv --distribute
$ source venv/bin/activate
$ pip install flask-restless
$ pip install flask-sqlalchemy # it doesn't appear to do this automatically
... Copy code from quickstart to "run.py" ...
$ python ./run.py
(another window)
$ curl -i http://127.0.0.1:5000/
The console output from run.py is:
* Running on http://127.0.0.1:5000/
* Restarting with reloader
127.0.0.1 - - [16/Apr/2013 17:08:05] "GET / HTTP/1.1" 404 -
The test.db does get created, and using the debugger I can see that app.run() does execute.
Interestingly, I get exactly the same behavior with Eve. I am able to run simple Flask apps, however.
In case it matters, this is OS X 10.8 and Python 2.7.3.
From the Flask-Restless documentation...
By default, the API for Person, in the above code samples, will be
accessible at http://<host>:<port>/api/person, where the person part
of the URL is the value of Person.__tablename__:
My guess is that by default, these frameworks do not set up an endpoint on the path /. They only have endpoints defined for paths related to actual objects in your API. Try the following...
curl -i http://127.0.0.1:5000/api/person
curl -i http://127.0.0.1:5000/person
These URLs might actually hit your endpoints that you're defining.
Related
When I try to do a pip install Flask I get some ssl errors. If I try to add exceptions there is no difference. I googled around and see some discussion on this from a year ago but nothing else (see https://github.com/pypa/pip/issues/5063)
(venv) pip install -U flask --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
Collecting flask
Could not fetch URL https://pypi.python.org/simple/flask/: There was a problem confirming
the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Could not find a version that satisfies the requirement flask (from versions: )
No matching distribution found for flask
NOTE : THIS MIGHT ALREADY SOMETHING THAT YOU HAVE TRIED
This is probably due to the fact that you are using --trusted-host=pypi.python.org .
This has happened since sometime during April 2018, the Python Package Index was migrated from pypi.python.org to pypi.org. This means "trusted-host" commands using the old domain no longer work.
So the command you are looking for would be pip install -U flask --trusted-host pypi.org --trusted-host=files.pythonhosted.org.
For furthur details , have a look at this this.
I'm setting up the virtual environment of Django for the first time. I've downloaded the Anaconda library of Python in my D drive. So initially I set up the path of Python and Conda(Scripts) manually in advance system settings. But now when I'm creating the environment using command
conda create --name mydjang0 django
the command prompt is showing an error like this-
C:\Users\AABHA GAUTAM> conda create --name mydjang0 django
Solving environment: failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/pro/win-64/repodata.json.bz2>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.
SSLError(MaxRetryError('HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/pro/win-64/repodata.json.bz2 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))'))
If you already have a .condarc file in your root folder. Then update the file by running this command.
conda config --set ssl_verify false
If you do not have a .condarc file, then create one and then run the above command. I have added both the commands below.
conda config --add channels conda-forge
conda config --set ssl_verify false
Instead of using command prompt use Anaconda Prompt as administator.
run the same command there.
I also faced same issue with command prompt.
Only delete file .condrac from c:\users\user
I have Flask application named as rest.py and I have dockerize but it is not running.
#!flask/bin/python
from flask import Flask, jsonify
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
}
]
#app.route('/tasks', methods=['GET'])
def get_tasks():
return jsonify({'tasks': tasks})
if __name__ == '__main__':
app.run(debug=True)
Dockerfile is as follows
FROM ubuntu
RUN apt-get update -y
RUN apt-get install -y python-dev python-pip
COPY . /rest
WORKDIR /rest
RUN pip install -r Req.txt
ENTRYPOINT ["python"]
CMD ["rest.py"]
I have build it using this command...
$ docker build -t flask-sample-one:latest
...and when I run container...
$ docker run -d -p 5000:5000 flask-sample-one
returning the following output:
7d1ccd4a4471284127a5f4579427dd106df499e15b868f39fa0ebce84c494a42
What am I doing wrong?
The output you get is the container ID. Check with docker ps whether it keeps running.
Use docker logs [container-id] to figure out what's going on inside.
Some problems I can find in your question:
Change the app.run line to app.run(host='0.0.0.0', debug=True). From the point of view of the container, its services need to be externally available. So they need to run on the loopback interface, like you would run it if you'd set up a publicly available server on a host directly.
Make sure that Flask gets installed. Your docker image file requires all the commands to make it work from a blank Ubuntu installation.
Please do not forget to deactivate debug if you'd ever expose this service on your host. Debug mode in Flask makes it possible for visitors to run arbitrary code if they can trigger an exception (it's a feature, not a bug).
After that (and building the container again [1]), try curl http://127.0.0.1:5000/tasks on the host. Let me know if it works, if not there are other problems in your setup.
[1] You can improve the prototyping workflow with Flask's built-in reloader (which is enabled by default) if you use a volume mount in your docker container for the directory that contains your python files - this would allow you to change your script on the host, reload in the browser and directly see the result.
I believe that you need to reinforce your concepts about Docker, in order to understand how it works, and then you will achieve your objectives regarding "dockerizing" whatever application.
Here is an article which can give your some first steps.
An official HOWTO will also help you.
Some observations that might help you:
check if your Req.txt contains flask for installation
before dockerizing, check if your application is working
check your running containers with docker ps and see if your container is running
if it is running, test your application: curl http://127.0.0.1:5000/tasks
*
One more thing:
your JSON has an OBJECT with an ARRAY with just one ELEMENT
Is that what you want for your prototype?
Take a look on this doc, about the JSON standard.
I have a Django project that I deploy on a server using CircleCI. The server is a basic cloud server, and I can SSH into it.
I set up the deployment section of my circle.yml file, and everything is working fine. I would like to automatically perform some actions on the server after the deployment (such as migrating the database or reloading gunicorn).
I there a way to do that with CircleCI? I looked in the docs but couldn't find anything related to this particular problem. I also tried to put ssh user#my_server_ip after my deployment step, but then I get stuck and cannot perform any action. I can successfully SSH in, but the rest of the commands is not called.
Here is what my ideal circle.yml file would look like:
deployment:
staging:
branch: develop
commands:
- rsync --update ./requirements.txt user#server:/home/user/requirements.txt
- rsync -r --update ./myapp/ user#server:/home/user/myapp/
- ssh user#server
- workon myapp_venv
- cd /home/user/
- pip install -r requirements.txt
I solved the problem by putting a post_deploy.sh file on the server, and putting this line on the circle.yml:
ssh -i ~/.ssh/id_myhost user#server 'post_deploy.sh'
It executes the instructions in the post_deploy.sh file, which is exactly what I wanted.
I am trying to send a GET request through postman using file URI scheme. An example:
file:///absolute/path/to/file.txt
The request works properly in any browser, but postman is failing with message:
Could not get any response
This seems to be like an error connecting to file:///absolute/path/to/file.txt
Is there any way to make postman work with file URIs?
Postman does not support file URIs, because the Chrome App platform does not allow direct access to files.
It should be easy to start a small HTTP server yourself though.. if you are on Mac/Linux, you can serve files in a directory using Python:
$ cd /path/to/directory/
$ python -m SimpleHTTPServer 1234
You can then visit
http://localhost:1234/filename
which will serve up the file.
Good answer.
I am not acquainted with SimpleHTTPServer, so I used live-server instead.
I followed the instructions at 2. Install and Run a Local Web Server to install live-server.
Then:
cd /path/to/(myJSONfile.json)
live-server <myJSONfile.json>
and the JSON file was opened in my default web browser.
Finally, in Postman I made a normal GET request, but on the address
http://127.0.0.1:8080.
It all worked just as intended.
In addition to czardoz's answer, for Python 3, SimpleHttpServer has been replaced by http.server. So, to serve the files using Python 3.x:
$ cd/path-to-directory/
$ python -m http.server 1234
Then, browse the file using:
http://localhost:1234/filename