Skip to content Skip to sidebar Skip to footer

Flask Apache On Aws Ec2 - Read/write Failing

So I've been stumped by this problem for a day now. I'm relatively new to AWS EC2 so have been experimenting with Python Flask apps on it. I have an Ubuntu instance, and can get a

Solution 1:

On thing that eats my eyes is that '__ file __' is in quotes. It is a special variable, not a string. It should not be quoted.

You may want to print you basePath variable first to see the actual path you get back.

Additionally, for cross platform compatibility, you may want to use os.path.sep instead of '/' as well as for the path concatenation use os.path.join instead of simple string concat.

Solution 2:

Probably related to this question, solution for the edit part is to convert the relative path to an absolute path. I do not know how programs are started on EC2 but it appears that the working directory is within some Python / library directory where the actual program is not allowed to write. A fix might look like so:

@ImgResizeApi.route('/test')deftest():
        f = open('/tmp/test.txt', 'w')
        f.write('Hi there')
        f.close()
        return render_template('index.html')

Post a Comment for "Flask Apache On Aws Ec2 - Read/write Failing"