Problem running Heroku's Facebook app tutorial with Python - python

I am testing Heroku's ability to write a Facebook app with Python. I'm having a problem running the basic tutorial. It seemed like this question was worth asking on StackOverflow in case there's an answer that helps other people who run into the exact same problem.
I followed the instructions on heroku's facebook development page (http://devcenter.heroku.com/articles/facebook). Deploying to Heroku worked fine.
However, running the app locally does not. When I follow the instructions and bring up
http://localhost:5000
I get to the Facebook Login screen. But when I click Log In on that screen, I get:
SSL connection error Unable to make a secure connection to the
server. This may be a problem with the server, or it may be requiring
a client authentication certificate that you don't have. Error 107
(net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.
and the console output is
09:55:07 web.1 | https://localhost:5000/ 09:55:07 web.1 |
https://www.facebook.com/dialog/oauth?client_id=179852202088814&redirect_uri=https://localhost:5000/&scope=user_likes,user_photos,user_photo_video_tags
09:55:07 web.1 | 127.0.0.1 - - [24/Sep/2011 09:55:07] "GET / HTTP/1.1"
302 - 09:59:02 web.1 | 127.0.0.1 - - [24/Sep/2011 09:59:02] code 400,
message Bad request syntax
('\x16\x03\x00\x00U\x01\x00\x00Q\x03\x00N}\xe2&\xf9\xf7"\x15\xd5\xb6\xf6\xa6\x0f\xb01\x97N\xcc\xb3l\xed\x97\xd1!-\x91c?\x1f\xac\xa2h\x00\x00*\x00\xff\x00\x88\x00\x87\x009\x008\x00\x84\x005\x00E\x00D\x00f\x003\x002\x00\x96\x00A\x00\x04\x00\x05\x00/\x00\x16\x00\x13\xfe\xff\x00')
09:59:02 web.1 | 127.0.0.1 - - [24/Sep/2011 09:59:02]
"UQN}?&??"ն??1?N̳l??!-?c???h*???98?5EDf32?A/??" 400 -
When I try it in Safari, the address bar shows the following very long URL:
https://localhost:5000/?code=AQBPWpkbRdL2bt7KER0fcUS9ZnheXiGApkaF5MXbNgyIJqzw46SGve1iVyLIx1sDltNh0PkXPDdxhjAxoa1YED1cpcaflCXCkqzO27A-rhgjBpXwWUClpGRpRmDD2eIXcOyIczo_qGf45tbpvDZO5hFa0gmUeSHri4vY3bqw-5jBjZRoZfEB7pI8cLPOIsnNICI#_=_
Safari compains that it can't establish a secure connection.
This is running on OS X 10.6.8.

This is because https is not enabled locally on your machine, you could enable this or you could alternatively run without the SSL on your localhost. To do this you would edit the function to look something like:
def get_home():
return 'http://' + request.host + '/'

Related

Flutter Web and logging on iPhone

I have a Flutter Web app with an iOS Safari-specific error. To debug it I create a build (flutter build web) and run Python's http.server (python3 -m http.server), then use ngrok to be able to open the app on my mobile device.
To be able to see logs I use OverlayEntry with Text, but it's not very convenient.
Python's http.server does some logging that looks like this:
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [10/Sep/2022 20:05:06] "GET / HTTP/1.1" 200 -
::1 - - [10/Sep/2022 20:05:07] "GET /flutter.js HTTP/1.1" 304 -
Is it possible to log something from a Flutter app to see it inside Python's http.server logs?
Yes, it's possible. You can use print() to log something to the console. You can also use the dart:developer package to log to the browser's console. Example:
import 'dart:developer' as developer;
developer.log('Hello world!', name: 'my.app.category');

Unable to connect Google App Engine to CloudSQL Postgres (via SQLAlchemy) in cloud shell

Running a small web app on Google App Engine (Flexible) using Python 3, Flask, SQLAlchemy, the psycopg2-binary package, and CloudSQL Postgres. The app connects to CloudSQL properly in my local dev environment (I use the proxy), but it won't seem to connect when deployed in the cloud.
Worked fine the first time I deployed it last week. After pushing an update and re-deploying, the app no longer connects to CloudSQL in the cloud shell or when deployed -- even after rolling back to that previous commit. But it connects just fine on my local dev machine using the proxy.
I've verified through debugging that the necessary credentials are being properly inserted in my SQLALCHEMY_DATABASE_URI, which is: postgres+psycopg2://[user]:[pw]#/[db_name]?host=/cloudsql/breadsheet:us-west1:breadsheet.
Only change I've made on the platform since the initial deploy was upgrading from Cloud Datastore to Firestore, which is where I'm pulling my environment variables from to build the URI. No data ever came from Datastore, so that shouldn't matter.
I'm following the GAE Postgres connection guide for Unix. Here's my app.yaml:
runtime: python
env: flex
instance_class: F1
entrypoint: gunicorn -w 1 breadsheet:breadapp
error_handlers:
- file: app/templates/errors/default_error.html
- error_code: over_quota
file: app/templates/errors/over_quota.html
beta_settings:
cloud_sql_instances: breadsheet:us-west1:breadsheet
Here's the error when I run gunicorn from the cloud shell:
(venv) [me]#cloudshell:~/breadsheet (breadsheet)$ gunicorn -w 1 breadsheet:breadapp
[2019-04-07 10:23:16 -0700] [471] [INFO] Starting gunicorn 19.9.0
[2019-04-07 10:23:16 -0700] [471] [INFO] Listening at: http://127.0.0.1:8000 (471)
[2019-04-07 10:23:16 -0700] [471] [INFO] Using worker: sync
[2019-04-07 10:23:16 -0700] [474] [INFO] Booting worker with pid: 474
2019-04-07 09:40:08,838 Exception on / [GET]
Traceback (most recent call last):
[...]
File "/home/[me]/breadsheet/venv/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 437, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/[me]/breadsheet/venv/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/breadsheet:us-west1:breadsheet/.s.PGSQL.5432"?
The above exception was the direct cause of the following exception:
[line of code with the first database call in my app]
[...]
File "/home/[me]/breadsheet/venv/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/cloudsql/breadsheet:us-west1:breadsheet/.s.PGSQL.5432"?
Tried the following (and more!) to no avail:
Whitelisting various IPs in CloudSQL management
Adjusting IAM permissions
Using nano to comment out the Firestore code and hard-code the URI
Using nano to hard-code the SQLALCHEMY_DATABASE_URI under env_variables in my app.yaml
What to try next?
For those reading this via search in the future, I had previously skipped the export SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://[USER]:[PW]#127.0.0.1:5432/[DB_NAME] because I didn't particularly care about the cloud shell environment and assumed it wouldn't make a difference for deployment. Apparently it does.
Later, when troubleshooting the db connection in cloud shell, I found myself skipping the first part (sudo mkdir /cloudsql;) of this two-step command sudo mkdir /cloudsql; sudo chmod 777 /cloudsql because I had already created the /cloudsql folder. I'm still not sure why both parts of the command are needed -- especially when the folder already exists -- but the db connection didn't work for me without them both.
One more note: setting SQLALCHEMY_DATABASE_URI under env_variables: in the app.yaml is not required, provided you set that value elsewhere in the app. Adding to the env_variables: simply makes the value available as an easily-accessible variable.

Can't get even a simple uwsgi test to work

I'm trying to get nginx/django/uwsgi set up, and I'm stuck at the first step. I'm just trying to get uwsgi to serve a test application directly to my browser, as described here as a basic test.
So, I create the test.py file:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"]
And then I start it up with $ uwsgi --plugins python --http :8001 --wsgi-file test.py
The output appears to be OK. I get the message WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x3a14c8 pid: 8295 (default app). I would expect that I would then be able to aim my browser at 127.0.0.1:8001, and see a hello world message. However, chrome just tells me that the site can't be reached.
I've been trying various permutations of tests from all over the internet for a solid day, but this is the simplest test I've found, and no one mentions what to do if it fails.
For reference, I'm using uwsgi 2.0.15 and python 3.6.1 on Arch.
EDIT: Evidently someone thought my question "did not show any research effort." So, to summarize what I've tried:
I checked that iptables wasn't blocking anything
I tried it on various ports
I tried moving on with the tutorial to see if it works with a real django project
I tried doing this all in a virtualenv
I tried running from a uwsgi ini file instead of the command line
I tried starting over any using various other tutorials.
Read this post and tried the answer
Output of $ curl -v 127.0.0.1:8001:
* Rebuilt URL to: 127.0.0.1:8001/
* Trying 127.0.0.1...
* TCP_NODELAY set
* connect to 127.0.0.1 port 8001 failed: Connection refused
* Failed to connect to 127.0.0.1 port 8001: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 8001: Connection refused
Please let me know if you can think of anything else.

Uploading django app to digitalocean server: 502 bad gateway nginx/1.4.6 (Ubuntu)

I'm using the following tutorial to upload a django webapp to a digital ocean server. Everything seems fine while entering the following commands:
pip install --upgrade django
service gunicorn restart
According to the tutorial I now should be able to see my webpage (without the bootstrap theme/fonts) after refreshing the host ip in my browser. Instead I get the following error:
I've looked up the nginx error.log in /var/log/nginx/error.log and it says the following:
2017/01/20 08:18:23 [error] 9342#0: *38 recv() failed (104:
Connection reset by peer) while reading response header from
upstream, client: 92.111.75.86, server: _, request: "GET / HTTP/1.1",
upstream: "http://127.0.0.1:9000/", host: "104.236.68.12"
Question: How do I fix this 502 bad gateway so that my site works properly? I've tried to add ALLOWED_HOSTS = ['104.236.68.12'] to settings.py already and I've also tried to create a droplet with ubuntu 16.04 as well.
You should add the IP address of your DigitalOcean droplet to the ALLOWED_HOSTS variable in your Django settings. Starting from your nginx log, I would set:
ALLOWED_HOSTS = ['104.236.68.12']
P.S: Consider to adopt Docker for the deployment of your django app
I'm so sorry guys. This solved the issue...
Dragging my django app in filezilla to
home/django/django_project
instead of:
home/django/django_project/django_project
Basically wasn't precise enough when reading the tutorial, so sorry!
Good day:
In the settings.py exactly in
ALLOWED_HOSTS = ['*']
This will make it collect all the ips.

In zulip dev environment, how can i access zulip's first dev web browser using run-dev.py in vagrant env but i can't access from global ip

I have some problem now using zulip dev-env ...
I did success-installation by Dev-env(using run-dev.py in vagrant env) in my Mac PC and then i could access the first-dev page successfully through my mac-pc's browser
But i have been trying to show the first page using Dev-dev in my cloud hosting service (like AWS or google Cloud hosting) for several days
but i could not access and could not show the first page by using global IP and browser
Which part must I change the setting environment?
(that is, I want to access my dev-env[using run-dev.py] by global IP
after that, i want to test... )
Now I am using a cloud hosting. Of course I opened port 9991 and etc...
I use vagrant env and succeed it in cloud host.
In vagrant ssh, I could access zulip by using curl 127.0.0.1:9991 and received a success message:
29/Sep/2016 00:42:04]"GET / HTTP/1.0" 302 0" from running console
but i cannot access it by host console like this
ai2#mrtalk:~/project/zulip$ curl 127.0.0.1:9991
curl: (7) Failed to connect to 127.0.0.1 port 9991: Connection refused
of course , i can't access http://182.162.90.79:9991/ through my pc browser
for this I tried like these
In zproject/dev_setting.py (I changed...these lines)
EXTERNAL_HOST = '0.0.0.0:9991' #orgin localhost but change 0.0.0.0
ALLOWED_HOSTS = ['localhost','182.162.90.79','0.0.0.0'] #orgin localhost but add + '182.162.90.79','0.0.0.0'
In Vagrantfile I changed this line:
config.vm.network "forwarded_port", guest: 9991, host: host_port, host_ip: 127.0.0.1, auto_correct: true
What is wrong with here? Or which part should I change my dev-setting?

Categories

Resources