Forums

Cannot extract .zip files

I've found one very important bug. From the website (http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms) I have downloaded the .zip file below. I know, I know, many online ftp editors are struggling with .zip files and other archives, but I have downloaded this .zip file and I wanted to extract it, but the only options for .zip files are: "download" or "delete". And that while I wanted to use this .zip file to test the functionality of this website, because I considered upgrading to a Hacker account or something (I now have a N00b account) but this bug is too important for me.
Is there some workaround for this bug? Or will it be fixed in the future? Because I love cloud editing too much.

unzip is available to users, just open a bash shell and run it there.

How should I do that considering I have a web app using the Flask framework? How could I go to that specific file, then extract it? Maybe a button would be nicer. I am now at a stage where I only copy scripts from the web and I do not understand much about Python yet.

@rbkkr95: Okay, so your web app allowed you to put the zip file on your PA server file space. As glenn was saying you could open a console to do the extraction, but it sounds like you are saying you need it done from within your web app for all your users to do? In that case, just code it in Python with a subprocess and tie that to the button you want in your web app.

You have at the right side of all files inside the file browser the "download" and "delete" button. Between those buttons, I want the "extract" button to be available when it is a .zip file. Do you get that? Is that a logical question? Because I do not know how to handle bash shells, and it is even getting harder with web apps because you have to know the path of that file, am I right?

@rbkkr95: It seems you are saying you don't like the fact that Flask is missing a feature that you want. I don't understand how that is a bug on PA. I've never used Flask, so I don't know, but I'd imagine you can add this extract button that you want to have. In order to locate the path of a file you can type the following in a bash console:

which %command%

The response will be:

/path/to/%command%

So, for instance the process for Firefox (Iceweasel) on PA looks something like this:

13:02 ~ $ which firefox
/usr/bin/firefox
13:04 ~ $

Oops...I re-read your last post after my post. You are talking about the PA Dashboard Files tab aren't you?

So, you just need to do what glenn said. If you have more questions about it. We're all glad to help. Try it and see how it works for you...☺

@rbkkr95, I'm a little confused. I understand the request for an "extract" button on the list of files. That's something that we probably won't implement - there are a million things that you could do to a file and we could spend all our development time making buttons for those and never do anything interesting. If you're serious about learning to program, time spent learning how to use bash will pay for itself many times over.

The bit that confuses me is how this relates to a Flask web app. Are you using a web app to upload a zip file and then you want to extract it so you can view its contents? Or did you download the microblog application from the tutorial and you want to run that as a webapp? If it's the latter, then learning how to unzip a file in a bash console is going to seem laughably easy by the time you have a working web app, but we'll be here to help.

After looking at http://docs.python.org/2/library/zipfile#zipfile.ZipFile.extract I realize I have to implement security to my script before I run it. I have to do all of this even before I can start learning Python... What I just wanted is to test that microblog app to see that this works and I think others might have that problem too. It is confusing me a lot and I feel like I cannot test other scripts now because I cannot extract the .zip files in a secure way (for example I have to test whether that .zip file really exists, then I have to test whether it is readable/writable/etcetera, then I have to check whether it is already extracted, then I have to choose the folder where I want to extract the file, and I have to make my own Python library for extracting files in the future, because I want to reuse the script, okay, maybe programming is getting too complicated for me and not so "laughably easy" as you might think when you're starting). I am not blaming you, of course, security is just very hard to accomplish.

@rbkkr95: Programming is laughably easy when you look at the right sized problem. After all it can all be distilled down to a 1 or a 0. That is laughably easy, so if what you are looking at is intimidating you are looking at too much and need to break it up. And then break it up again and again and again until you have a manageable problem. That is the essence of programming. And the thinking style it teaches you will pay dividends in all of life!!

As to your issue now. Stop thinking so BIG!!!!! For now just use the bash console to extract your zip file like you've been advised. Then play around with it to learn. Once you get a foundation, things will certainly begin to come together!

Another idea would be to go a different direction. If it feels like you need to lay too much groundwork to complete your current plan, perhaps you should follow a tutorial or something to begin the learning process. Then come back to what you are trying to do now.

Whatever you choose we are here to help. Don't give up, just keep asking questions. We'll solve it together if you stick with it. The choice is entirely yours...☺

SOLVED. The issue was finding the right code to extract it, and finding the right path of the .zip file and the directory. The files currently inside "mysite":

microblog-0.3/  
extract.py                                       118 bytes
flask_app.pyc                732 bytes
microblog-0.3.zip                52.5 KB

And the code of "extract.py":

import zipfile
zip = zipfile.ZipFile('/home/rbkkr95/mysite/microblog-0.3.zip')
zip.extractall('/home/rbkkr95/mysite/')

Please press "Save & Run" to extract the .zip file. In my case, the file was extracted succesfully, but I got the error, after going to "rbkkr95.pythonanywhere.com":

Unhandled Exception

Maybe that is fine, but what is the exception then? I do not know that, so there are no other errors than this weird error. So I cannot really know what I have done wrong.

Cool. Progress, at least. I had a quick look at your files and wsgi setup. In your web app dir, theres a flask_app.pyc which looks like a left-over from a previous Flask app that ran from ~/mysite (possibly from an old quickstart). That's what is returning the 'Unhandled exception'

The unzip that you did has created a new folder in mysite which is where the tutorial app is, now and your wsgi file doesn't point to it, it just points to ~/mysite. There is a link to your wsgi file on your web app tab (it's in /var/www/rbkkr95_pythonanywhere_com_wsgi.py) You'll want to change this line:

project_home = u'/home/rbkkr95/mysite'

to

project_home = u'/home/rbkkr95/mysite/microblog-0.3'

and this line

from flask_app import app as application

to something like

from app import app as application

That should mean that your web application knows where to find the code it's supposed to run.

Having read a bit of the tutorial, though, I suspect it still won't work because there are additional setup steps that are a necessary part of the tutorial and you've skipped them out. It seems to me like the tutorial is not really meant as a "download this and it will work" kind of thing. It's more of a "follow along and you'll learn how to do this" kind of thing.

UNHANDLED EXCEPTION SOLVED Cool, it works now like it should. Please have a look at my website now. A real website is visible now with the contents that it should have. Now I really want to move from PHP to Python, because it handles libraries and apps better than PHP. Thank you for the great help which you only could have given me, because you know the most about your Services. It be helpful to other free users that start with Python and want to test how the language works.

That's excellent. Looks like it's working. I suspect that you'll bump into other issues as you use the microblog, and learn more Python. We're always here to help.

@rbkkr95: Out of interest, are you following an online Python tutorial of some sort, or just the Flask one you linked? As you go along you'll probably found a general overview of the Python language helpful - there are quite a few things which work a little differently than PHP and you might save yourself some confusion later if you do a bit of background reading first. If you're fairly experienced already in other languages I can recommend Dive Into Python for something that gets you up to speed fast, or the official Python tutorial is also good if you want something a little more slow paced. From what little I've skimmed through, Learning Python The Hard Way is also good if you're planning to use the language in a serious way.

However, those are just suggestions - if you prefer to jump in and learn by doing, that's fine too, of course. Just keep an open mind that you might need to go back an unlearn some bad habits that you pick up initially! (^_^)

As an aside, I would certainly say that moving from PHP to Python is a good idea - PHP gets the job done, but has so many little flaws it's been referred to as a fractal of bad design by some. Personally I think that's a little harsh, but it's quite a messy language that starts to struggle once you get outside the realm of web development, or once your system gets large. Python, on the other hand, scales beautifully to large systems, has a clean consistent design which is equally useful for tiny scripts and massive applications, and is generally a pleasant tool to use. Web development may take a little more up-front effort with Python than PHP, but if your application grows to any size then you'll certainly appreciate the benefits.

This is a cool site for practicing using Python to solve issues. And best of all, it gives feedback!!

Hm, that looks like a handy resource for beginners. For anybody looking for a bit more of an advanced challenge (not Python-specific) try Project Euler. I spent a few weeks having a go at those a few years ago - according to my login, I solved problems 1-69, all in Python. It's a bit depressing to see how many new problems have been added since!

EDIT: I should point out that from what I can remember, Project Euler's problems get quite tricky quite quickly, and you need to be somewhat mathematical to approach most of them. If you're easily frustrated, it might be a good idea to stay away. It's more about selecting a good algorithm than proficiency with a specific language. Still, it's a lot of fun, if you enjoy that sort of thing. I suppose most things are.

I've seen Project Euler before, but never created an id. The sheer number of problems is so overwhelming. It would have been nice to come across it when there were only 69 problems...☺

Ah, no, there were plenty more than 69, but not nearly as many as now. Still, it's not the sort of site where you should feel obliged to solve them all, or even in order - you pick something that sounds interesting and give it a go. Except for an easy few, I think it used to take me at least half an hour to get solutions to most of them. Getting an answer isn't so hard if you can run overnight and brute force it, but a "proper" solution by their rules should run in under a minute on even a modest modern PC.

In under a minute...What if I write my solutions on PiCloud? Okay, just being silly. I guess I'm in one of those moods.

It must be my excitement that Patch Tuesday only had ONE update!!!

Only one? My machine wants to install 8 :-(

If it makes you feel better...my ONE update required a restart...:(

Still not a lot compared to the average Ubuntu update, though? I'm quite grumpy about Ubuntu right now as I just had to spend 10 minutes untangling some aptitude mess where it thought that some non-existent package called 3:php5-cli had stolen ownership of php.ini from php5-cli, and the latter was throwing a hissy fit about it. Still, at least I've learned a little bit about the ucfr utility - mostly what I've learned is that I'm not particularly keen on learning any more.

hands Cartroo a cookie & some milk...I hope that helps ease the pain!!

@Cartroo -- well, I guess that's another reason why we need to avoid supporting PHP on PythonAnywhere ;-)

@a2j -- my machine wants to reboot too, but I'm building a new PythonAnywhere cluster from Arch in a VirtualBox VM that's running on it so I'm definitely not going to reboot until that's live.

(BTW if it all comes up correctly then this is the change that switches our fileserver image over to Ubuntu -- we'll be deploying it at 4am UTC tonight, so wish us luck!)

[UPDATE] we're definitely going ahead with that upgrade tonight. The new cluster is up and running (but not connected to the live user storage volumes yet) and it looks healthy.

SWEET!!

+1 for completing a task.

@giles: Here is a piece of π for you to eat while you wait for your workstation to reboot now that the cluster is built...☺

@giles: As if you needed more reasons... Good luck with the upgrade. Plenty of Hot Lava Java being consumed tonight, I'll wager.

@a2j don't worry, since I overclocked it I'll have some hot raspberry pi...

@Cartroo absolutely! Taking a break now and back into the office shortly...

I tried overclocking my pi... But then the wireless USB keyboard started suffering from "stuck key" issues, which was quite annoying, so I clocked it back down.

Having said that I still see them sometimes when I reboot, so it's probably just down to naff hardware or a naff driver [A naff driver in the Linux kernel? Shome mishtake, shurely? -Ed] - still, it put me off the whole business, and as basically an SSH endpoint for home it doesn't really need any CPU to speak of.

You were right. I'm indeed having a problem, maybe very specific to the libraries of PythonAnywhere. I'm at part IV now, please have a look at this template:

http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database.

I've tried to Save & Run the file

db_create.py

having this code:

#!flask/bin/python
 from migrate.versioning import api
 from config import SQLALCHEMY_DATABASE_URI
 from config import SQLALCHEMY_MIGRATE_REPO
 from app import db
 import os.path
 db.create_all()
 if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
     api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
      api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  else:
     api.version_control( SQLALCHEMY_DATABASE_URI, 
      SQLALCHEMY_MIGRATE_REPO,   api.version(SQLALCHEMY_MIGRATE_REPO))

This gives the following error inside the console:

 Traceback (most recent call last):
 File "/home/rbkkr95/mysite/microblog-0.3/db_create.py", line 2, in <module>                                                                               
 from migrate.versioning import api                                                                                                                      
  ImportError: No module named migrate.versioning                                                                                                             
  >>>

I conclude there is no API called "migrate.versioning" and I do not have any idea how to download this. Please provide me any additional information. I've already completed the previous steps inside the tutorial, but I think this file could be run apart from the other scripts. Is that true? I hope I have given you enough information about this error report.

It looks like we're missing some of the packages that the tutorial relies on. You can install them for yourself like this in a Bash shell:

pip install --user sqlalchemy-migrate
pip install --user flask-whooshalchemy

We'll get those installed for everyone, but with our current release schedule, it may only be ready in about a week.

The installation of both packages that I rely on was succesful. But after running

db_create.py

I have gotten the following error:

Traceback (most recent call last):
   File "/home/rbkkr95/mysite/microblog-0.3/db_create.py", line 2, 
 in <module>                                                       
    from migrate.versioning import api                            
    File "/home/rbkkr95/.local/lib/python2.7/site-packages/migrate/versioning/api.py", line 33, in <module>                           
    from migrate.versioning import (repository, schema, version,  
    File "/home/rbkkr95/.local/lib/python2.7/site-packages/migrate/versioning/schema.py", line 10, in <module>                        
   from sqlalchemy import exceptions as sa_exceptions            
  ImportError: cannot import name exceptions                        
   >>>

What have I done wrong? Could this be correctable? I love hacking around a little bit with the Bash shall and such, but I have to get used to the different commands.

According to this bug it looks like the exceptions module was renamed exc, so if you're using version 0.8.0 onwards it sounds like the code would need to change.

Sounds like this is in a third party library, however, so I wonder if it's written to work with an earlier version of SQLAlchemy than you have installed? You can either try and fix the third party library, or install the earlier version.

(Assuming I'm correct about the source of the problem - try opening a Python shell and doing from sqlalchemy import exceptions and then from sqlalchemy import exc - if the first fails but the second works, then this is almost certainly the problem)

That was indeed my case after having run the two commands. The first one gave:

 from sqlalchemy import exceptions
 Traceback (most recent call last):                                                    
 File "<stdin>", line 1, in <module>                                                 
 ImportError: cannot import name exceptions

The second one worked errorlessly.
May I now assume that the tutorial is a wrong tutorial? Is it necessary to remove both packages? How could I achieve that?

EDIT

I have a N00b account, that is adequate for my needs. Now I want to exercise with Django instead of Flask, but I noticed the amount of web apps is limited by 1, meaning that I cannot learn multiple Python frameworks, while I'm not even graduated from secondary school, thus I now have no opportunities to be an all-round Python developer, whereas the importance of knowing multiple ways to achieve the same thing is high and very interesting too.

About the tutorial: It's not wrong, it's just that there's a version conflict between the tutorial and the packages we have installed on PythonAnywhere. The first page of the tutorial explains the versions necessary. You can create a virtualenv and install the correct version of everything as detailed on the first page of the tutorial. It's a little (but only a little) more complicated to use a virtualenv for a webapp. There's some detail here

About the one webapp thing: You are limited to one web app at a time. It's only a few clicks to switch between different web apps. With a little bit of clever scripting, you can do it with a single call.

Great, thanks for your help. After going to http://rbkkr95.pythonanywhere.com/, you'll see a succesful installation of the virtual environment. Some tips for other users:

Strictly follow the instructions.

If you have called a previously started web app "mysite", then call this new "virtual project" for example "djangomysite".

If you have already started a previous web app, then you'll notice that your wsgi file already contains some settings for that project. For example, I've started a Flask project, you would know that if you've read my previous forum messages carefully. If that's you're case too, then comment all the settings for your Flask project and put the new settings for this virtual environment inside the same wsgi file, below the commented settings for your Flask project.

I've changed the instructed piece of code

activate_this = '/home/virtualenvdemo/.virtualenvs/django14/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

path = '/home/virtualenvdemo/mysite'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

to my custom code:

activate_this = '/home/rbkkr95/.virtualenvs/django14/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys
path = '/home/rbkkr95/djangomysite'
if path not in sys.path:
       sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangomysite.settings'

EDIT

Even after the deletion of the "mysite" folder for my Flask project, the Django project still works. I will only use virtual environments now, because I love having multiple apps in the future.

That's excellent, @rbkkr95