How to publicly view website that I am hosting on amazon-ec2? - amazon-ec2

I have started an amazon-ec2 instance with public a DNS of ec2-12-34-567-89.us-west-2.compute.amazonaws.com. There I have set up a security group, where type=HTTP, protocol=TCP, port range=80, source=0.0.0.0/. I log in to the EC2 instance and launch my app:
$ python3 run.py
* Running on http://0.0.0.0:0/
Then with browser I try to open: http://ec2-12-34-567-89.us-west-2.compute.amazonaws.com and get an "Unable to connect" message.
What am I missing here?
Edit
With port 80, it ends up like this:
$ python3 run.py
* Running on http://0.0.0.0:80/
Traceback (most recent call last):
File "run.py", line 5, in <module>
app.run(host="0.0.0.0", port=80)
File "/opt/python/3.4.1/lib/python3.4/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/opt/python/3.4.1/lib/python3.4/site-packages/werkzeug/serving.py", line 710, in run_simple
inner()
File "/opt/python/3.4.1/lib/python3.4/site-packages/werkzeug/serving.py", line 692, in inner
passthrough_errors, ssl_context).serve_forever()
File "/opt/python/3.4.1/lib/python3.4/site-packages/werkzeug/serving.py", line 486, in make_server
passthrough_errors, ssl_context)
File "/opt/python/3.4.1/lib/python3.4/site-packages/werkzeug/serving.py", line 410, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/opt/python/3.4.1/lib/python3.4/socketserver.py", line 429, in __init__
self.server_bind()
File "/opt/python/3.4.1/lib/python3.4/http/server.py", line 133, in server_bind
socketserver.TCPServer.server_bind(self)
File "/opt/python/3.4.1/lib/python3.4/socketserver.py", line 440, in server_bind
self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied

Appearently I needed to run my code as superuser.
$ **sudo** python3 run.py
* Running on http://0.0.0.0:80/

Related

Cannot create fifo "[Errno 17] File Exists"

I see output like:
ERROR:duckietown_challenges:evaluation: weird exception: Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/zuper_nodes_wrapper/wrapper_outside.py", line 62, in __init__
os.mkfifo(fnin)
FileExistsError: [Errno 17] File exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/duckietown_experiment_manager/experiment_manager.py", line 34, in wrap
asyncio.run(main(cie, logdir, attempts), debug=True)
File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/usr/local/lib/python3.8/site-packages/duckietown_experiment_manager/code.py", line 211, in main
sim_ci = ComponentInterface(
File "/usr/local/lib/python3.8/site-packages/zuper_nodes_wrapper/wrapper_outside.py", line 65, in __init__
raise Exception(msg) from e
Exception: Cannot create fifo /fifos/simulator-in
This is running inside of a container so I'm not sure why or how I can control the existence or absence of this file.
The solution is to remove the volume, for example with
docker system prune --volumes

How to connect to MySQL with a Flask app on Heroku using SQLAlchemy [duplicate]

I uploaded a Django app to Heroku and than provision the cleardb add-on using these 3 commands from Heroku documentation:
heroku addons:create cleardb:ignite
heroku config | grep CLEARDB_DATABASE_URL
heroku config:set DATABASE_URL='mysql://adffdadf2341:adf4234#us-cdbr-east.cleardb.com/heroku_db?reconnect=true'
it seems to be O.K and the app is running (but without database).
now I try to run:
$ heroku run python manage.py migrate
and this is the error I get:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 327, in execute
self.check()
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/app/.heroku/python/lib/python3.5/site-packages/django/core/checks/database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/mysql/validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 274, in get_new_connection
conn = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.5/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/app/.heroku/python/lib/python3.5/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: 'reconnect' is an invalid keyword argument for this function
Where does the problem comes from and how can I fix it?
Remove ?reconnect=true from the end of DATABASE_URL
The parameters after the database are arguments to the MySQL server. In this case, it asks to reconnect if the connection is dropped. It looks like the MySQLdb package doesn't support that argument.

Apache Arrow connectivity issue with HDFS (Remote file-system)

I want to connect pyarrow to read to and write parquet file in hdfs
But I am facing some connectivity issue
I installed pyarrow and python pandas now I am trying to connect with hdfs
in remote machine
Reference link - https://towardsdatascience.com/a-gentle-introduction-to-apache-arrow-with-apache-spark-and-pandas-bb19ffe0ddae
import pyarrow as pa
host = '172.17.0.2'
port = 8020
fs = pa.hdfs.connect(host, port)
Error messages
>>> fs = pa.hdfs.connect(host, port)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/pyarrow/hdfs.py", line 211, in connect
extra_conf=extra_conf)
File "/usr/lib64/python2.7/site-packages/pyarrow/hdfs.py", line 36, in __init__
_maybe_set_hadoop_classpath()
File "/usr/lib64/python2.7/site-packages/pyarrow/hdfs.py", line 136, in _maybe_set_hadoop_classpath
classpath = _hadoop_classpath_glob('hadoop')
File "/usr/lib64/python2.7/site-packages/pyarrow/hdfs.py", line 161, in _hadoop_classpath_glob
return subprocess.check_output(hadoop_classpath_args)
File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Jupyter does not run with sagemath installed

I am running on a mac, with sagemath installed and Anaconda also.
Sage is working fine, though Jupyter notebook doesn't run.
I get the following error:
Rois-MBP:~ roi$ /anaconda/bin/jupyter_mac.command ; exit;
[W 22:32:09.192 NotebookApp] Unrecognized JSON config file version, assuming version 1
Traceback (most recent call last):
File "/anaconda/bin/jupyter-notebook", line 6, in <module>
sys.exit(notebook.notebookapp.main())
File "//anaconda/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "//anaconda/lib/python3.5/site-packages/traitlets/config/application.py", line 595, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "//anaconda/lib/python3.5/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "//anaconda/lib/python3.5/site-packages/notebook/notebookapp.py", line 1069, in initialize
self.init_configurables()
File "//anaconda/lib/python3.5/site-packages/notebook/notebookapp.py", line 837, in init_configurables
parent=self,
File "//anaconda/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 19, in __init__
specs = self.find_kernel_specs() or {}
File "//anaconda/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 129, in find_kernel_specs
self.conda_info = self._conda_info()
File "//anaconda/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 29, in _conda_info
p = subprocess.check_output(["conda", "info", "--json"]
File "//anaconda/lib/python3.5/subprocess.py", line 626, in check_output
**kwargs).stdout
File "//anaconda/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
File "//anaconda/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "//anaconda/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'conda'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Other apps like spyder do run successfully.
Can I solve it somehow?
Found a way to run jupyter notebook through sage:
Just run from the terminal: ./sage -n jupyter

Calling Raspberry Pi temp sensor, invalid syntax when calling driver as bash script

I'm currently putting together a temperature sensor for my Raspberry Pi and ran into this issue. In order to run the driver designated in the code, I had to run it was a shell command. I'm having a difficult time figuring out why my syntax is incorrect.
Code:
def read_dht22( PiPin ):
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)])
Error:
sudo python scr6.py
File "scr6.py", line 31
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver', '2302', str(PiPin)])
^
SyntaxError: invalid syntax
Error Prior to Adding shell=True
sudo python scr5.py
Traceback (most recent call last):
File "scr5.py", line 46, in <module>
temp_c, temp_f = read_dht22(4)
File "scr5.py", line 31, in read_dht22
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver", "2302", str(PiPin)])
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
This should fix your syntax error:
def read_dht22( PiPin ):
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True)

Resources