testing my GAE application with virtualenv in Python - python

I'm trying to test my datastore with unittest on my GAE application running locally
when i'm running a simple query on the datastore, I get an error from my virtualenv:
Error
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
testMethod()
File "/Users/thibault/projects/backend/cron/gmail/test_gmail_api.py", line 40, in test_get_conversation_id_by_email
res = get_conversation_id_from_email('test#gmail.com')
File "/Users/thibault/projects/backend/cron/gmail/api_gmail.py", line 158, in get_conversation_id_from_email
user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
return wrapped(*args, **kwds)
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1218, in fetch
return self.fetch_async(limit, **q_options).get_result()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/utils.py", line 160, in positional_wrapper
return wrapped(*args, **kwds)
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 1238, in fetch_async
qry = self._fix_namespace()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb/query.py", line 922, in _fix_namespace
namespace = namespace_manager.get_namespace()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/namespace_manager/namespace_manager.py", line 88, in get_namespace
name = _config.default_namespace_for_request()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 351, in __getattr__
self._update_configs()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 287, in _update_configs
self._registry.initialize()
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/api/lib_config.py", line 160, in initialize
import_func(self._modname)
File "/Users/thibault/projects/backend/appengine_config.py", line 8, in <module>
vendor.add('lib')
File "/Users/thibault/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory
I'm using the ide pycharm. I don't understand why it can't find the lib folder because, when I run my app locally, there is no problem at all.
the error append only when I run a test.
here is my test:
class TestBodyMail(unittest.TestCase):
def test_get_conversation_id_by_email(self):
res = get_conversation_id_from_email('test#gmail.com')
self.assertEqual(res,'2a4427fe77d2f0d2')
res = get_conversation_id_from_email('test#not_a_user.com')
self.assertEqual(res, None)
if __name__ == '__main__':
unittest.main()
the tested function:
def get_conversation_id_from_email(email_user):
"""
Args:
email_user: the email user
Returns:
the conversation id
"""
user_list = User.query(User.emails == email_user).fetch(use_cache=True, use_memcache=True)
if len(user_list) == 0:
return None
for user_match in user_list:
return user_match.device_ids[0]

Create appengine_config.py in the root of project, and put this:
import os
from google.appengine.ext import vendor
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
Also, add lib package into root of project if it is not there.
In my case it solved the issue.

Related

File not found in app hosted in pythonanywhere

There is an answer here - File not found on pythonanywhere.com
But it doesn't work in my case.
I have put the file in both the project main directory and the /project/static directory -
My code -
from flask import Flask, render_template, request
from flask_cors import CORS, cross_origin
from diffdiag import DifferentialDiagScript2 as dd
import os
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/*": {"origins": "*"}})
#app.route('/')
#cross_origin()
def index():
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, 'literature.csv')
items = list(line.strip() for line in open(file_path))
return render_template('index.html', table = items)
I have also tried -
items = list(line.strip() for line in open(f2))
items = list(line.strip() for line in open('./static/f2'))
items = list(line.strip() for line in open('/home/daddyodevil/add/Automated_DD/f2'))
items = list(line.strip() for line in open('/home/daddyodevil/add/Automated_DD/static/f2'))
Nothing seems to work.
Any help is appreciated.
Edit 1 - Adding complete error
Exception on / [GET]#012Traceback (most recent call last):#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app#012 response = self.full_dispatch_request()#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request#012 rv = self.handle_user_exception(e)#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function#012 return cors_after_request(app.make_response(f(*args, **kwargs)))#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception#012 reraise(exc_type, exc_value, tb)#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise#012 raise value#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request#012 rv = self.dispatch_request()#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request#012 return self.view_functions[rule.endpoint](**req.view_args)#012 File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask_cors/decorator.py", line 128, in wrapped_function#012 resp = make_response(f(*args, **kwargs))#012 File "/home/daddyodevil/add/Automated_DD/app.py", line 13, in index#012 items = list(line.strip() for line in open("./static/f2"))#012FileNotFoundError: [Errno 2] No such file or directory: './static/f2'
Edit 2 - Adding error received when trying to run app.py in pythonanywhere
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Traceback (most recent call last):
File "/home/daddyodevil/add/Automated_DD/app.py", line 47, in <module>
app.run()
File "/home/daddyodevil/.local/lib/python3.6/site-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/home/daddyodevil/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/home/daddyodevil/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/home/daddyodevil/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/home/daddyodevil/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/usr/lib/python3.6/socketserver.py", line 453, in __init__
self.server_bind()
File "/usr/lib/python3.6/http/server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.6/socketserver.py", line 467, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use
Running app.py in a PythonAnywhere console is unlikely to work -- it will try to bind to a port and listen for connections, and it's entirely possible that someone else is using the port.
The problem you're seeing in your website error log is because you're trying to open the file './static/f2'. This path with be resolved relative to the directory where the application is running, which is not necessarily the same as the directory containing the module, and might not be the main directory either.
If you want to load up the one in the same directory as the module, and you already have code to work out the module directory like this
module_dir = os.path.abspath(os.path.dirname(__file__))
...then you can change your code to use that module_dir by changing the line
items = list(line.strip() for line in open("./static/f2"))
...to be this:
items = list(line.strip() for line in open(os.path.join(module_dir, "./static/f2")))
The linked answer doesn't work for you because you haven't followed it properly. Wrap your module directory inside os.path.abspath() in order to get the absolute path as the linked answer suggests:
module_dir = os.path.abspath(os.path.dirname(__file__))
Edit
Also ensure that this file actually exists relative to your module directory:
'./static/f2'
Because that's where the exception is being thrown (look at the last line of the stack trace):
items = list(line.strip() for line in open("./static/f2"))
#012FileNotFoundError: [Errno 2] No such file or directory: './static/f2'

Boot up scrapyd failed with default configuration: sqlite3.OperationalError: unable to open database file

I just installed scrapyd on Ubuntu (with apt-get tool). However, without doing any change to the configuration, when I launched "scrapyd" I got the following error:
(! 397)-> scrapyd
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/application/app.py", line 642, in run
runApp(config)
File "/usr/lib/python2.7/dist-packages/twisted/scripts/twistd.py", line 23, in runApp
_SomeApplicationRunner(config).run()
File "/usr/lib/python2.7/dist-packages/twisted/application/app.py", line 376, in run
self.application = self.createOrGetApplication()
File "/usr/lib/python2.7/dist-packages/twisted/application/app.py", line 441, in createOrGetApplication
application = getApplication(self.config, passphrase)
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/application/app.py", line 452, in getApplication
application = service.loadApplication(filename, style, passphrase)
File "/usr/lib/python2.7/dist-packages/twisted/application/service.py", line 405, in loadApplication
application = sob.loadValueFromFile(filename, 'application', passphrase)
File "/usr/lib/python2.7/dist-packages/twisted/persisted/sob.py", line 210, in loadValueFromFile
exec fileObj in d, d
File "/usr/lib/pymodules/python2.7/scrapyd/txapp.py", line 3, in <module>
application = get_application()
File "/usr/lib/pymodules/python2.7/scrapyd/__init__.py", line 14, in get_application
return appfunc(config)
File "/usr/lib/pymodules/python2.7/scrapyd/app.py", line 22, in application
poller = QueuePoller(config)
File "/usr/lib/pymodules/python2.7/scrapyd/poller.py", line 13, in __init__
self.update_projects()
File "/usr/lib/pymodules/python2.7/scrapyd/poller.py", line 30, in update_projects
self.queues = get_spider_queues(self.config)
File "/usr/lib/pymodules/python2.7/scrapyd/utils.py", line 18, in get_spider_queues
d[project] = SqliteSpiderQueue(dbpath)
File "/usr/lib/pymodules/python2.7/scrapyd/spiderqueue.py", line 12, in __init__
self.q = JsonSqlitePriorityQueue(database, table)
File "/usr/lib/pymodules/python2.7/scrapyd/sqlite.py", line 95, in __init__
self.conn = sqlite3.connect(self.database, check_same_thread=False)
sqlite3.OperationalError: unable to open database file
Failed to load application: unable to open database file
I am pretty new to Python, I was trying to print the SQlite filename that it tried to open but this file is owned by scrapy user and I try to stay away messing with it. Also, here the content of my configuration:
(! 403)-> cat /etc/scrapyd/conf.d/000-default
[scrapyd]
http_port = 6800
debug = off
#max_proc = 1
eggs_dir = /var/lib/scrapyd/eggs
dbs_dir = /var/lib/scrapyd/dbs
items_dir = /var/lib/scrapyd/items
logs_dir = /var/log/scrapyd
Does anyone have clue about this? Thanks.
I suspect the Scrapyd configuration is referencing files or folders that your system user doesn't have the appropriate permissions to use.
There are at least three potential solutions to this problem:
Change the dbs_dir in the configuration file (/etc/scrapyd/scrapyd.conf) to a location your system user can access.
Change the permissions on /var/lib/scrapyd/dbs to allow users or groups access.
Run scrapyd as another user, as a superuser, or as root.

sqlalchemy: assert dispatch_reg[owner_ref] == listen_ref

I'm using Invenio 2.0 and try to replace old version of SQLAlchemy 0.8.7 with the last 0.9.7.
The utility to automaticaly create the db works (inveniomanage database recreate --yes-i-know).
But when I start tests with: python setup.py test
It return me a error:
test_fisrt_blueprint (invenio.testsuite.test_ext_template.TemplateLoaderCase) ... --------------------------------------------------------------------------------
ERROR in wrappers [/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/ext/logging/wrappers.py:310]:
--------------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/ext/legacy/__init__.py", line 124, in __call__
response = self.app.full_dispatch_request()
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/flask/app.py", line 1470, in full_dispatch_request
self.try_trigger_before_first_request_functions()
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/flask/app.py", line 1497, in try_trigger_before_first_request_functions
func()
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/views.py", line 264, in invoke_email_alert_register
email_alert_register()
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/models.py", line 202, in email_alert_register
event.listen(MsgMESSAGE, 'after_insert', email_alert)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/api.py", line 63, in listen
_event_key(target, identifier, fn).listen(*args, **kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 187, in listen
self.dispatch_target.dispatch._listen(self, *args, **kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/orm/events.py", line 547, in _listen
event_key.base_listen(**kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 226, in base_listen
for_modify(target.dispatch).append(self, propagate)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 328, in append
event_key.append_to_list(self, self.listeners)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 237, in append_to_list
_stored_in_collection(self, owner)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 74, in _stored_in_collection
assert dispatch_reg[owner_ref] == listen_ref
AssertionError
In /home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/views.py (row 264)
# Registration of email_alert invoked from blueprint
# in order to use before_app_first_request.
# Reading config CFG_WEBMESSAGE_EMAIL_ALERT
# required app context.
#blueprint.before_app_first_request
def invoke_email_alert_register():
email_alert_register()
In /home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/models.py (row 202)
# Registration of email_alert invoked from blueprint
# in order to use before_app_first_request.
# Reading config CFG_WEBMESSAGE_EMAIL_ALERT
# required app context.
def email_alert_register():
if cfg['CFG_WEBMESSAGE_EMAIL_ALERT']:
from sqlalchemy import event
# Register after insert callback.
event.listen(MsgMESSAGE, 'after_insert', email_alert)
Someone can help me?
Installed:
-e git+https://github.com/mitsuhiko/flask-sqlalchemy#c7eccba63314f3ea77e2c6217d3d3c8b0d2552fd#egg=Flask_SQLAlchemy-2.0
MySQL-python==1.2.5
SQLAlchemy==0.9.7
SQLAlchemy-Utils==0.23.5
With help from google (today) I found what I suspect would be a solution here (I'm not an invenio user)
I suspect an SQLa update will fix your issue.
https://bitbucket.org/zzzeek/sqlalchemy/issue/3199/deduplication-of-events-doesnt-work-for
-->
https://bitbucket.org/zzzeek/sqlalchemy/commits/9ae4db27b993
-->
Fixed in SQLA 0.9.8 (supposedly)

Flask-frozen don’t work whereas flask is ok

I have a website using Flask. The main program is pretty long, so I’ve used a paste to show you the code. When I run it with ./site serve --debug it works perfectly, but I can’t freeze it with Flask-frozen. I have this error :
$ ./site build
Building website...
./site:240: MimetypeMismatchWarning: Filename extension of u'sitemap.xml' (type application/xml) does not match Content-Type: text/html; charset=utf-8
freezer.freeze()
Traceback (most recent call last):
File "./site", line 346, in <module>
parser.dispatch()
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/helpers.py", line 53, in dispatch
return dispatch(self, *args, **kwargs)
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 123, in dispatch
for line in lines:
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 199, in _execute_command
for line in result:
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 182, in _call
result = args.function(*positional, **keywords)
File "./site", line 240, in build
freezer.freeze()
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 140, in freeze
new_filename = self._build_one(url)
File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 250, in _build_one
% (response.status, url))
ValueError: Unexpected status '500 INTERNAL SERVER ERROR' on URL /403.html
If I delete the part about 403.html in site.py, I have the same error with 404, then 500, then contact.html, then /. And I can’t find why. Is there anybody who has an idea ?
Enable testing while freezing your application. It should produce more information about error.
#command
def build():
""" Builds this site.
"""
print("Building website...")
app.debug = False
app.testing = True
asset_manager.config['ASSETS_DEBUG'] = False
freezer.freeze()
local("cp ./static/*.ico ./build/")
local("cp ./static/*.txt ./build/")
local("cp ./static/*.xml ./build/")
print("Done.")
Frozen-flask uses app.test_client() look at it's docs.

django-pipeline and s3boto storage don't seem to work together

I'm trying to use django-pipeline-1.1.27 with s3boto to compress and filter static files, and then upload them to an s3 bucket. If I just use:
PIPELINE_STORAGE = 'pipeline.storage.PipelineFinderStorage'
Then it works and I get a static folder with the nice versioned file that I configured. As soon as I switch to
PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
I get
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_manager(settings)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/management/commands/synccompress.py", line 39, in handle
packager.pack_stylesheets(package, sync=sync, force=force)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 52, in pack_stylesheets
**kwargs)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 60, in pack
package['output'], package['paths'])
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 45, in need_update
version = self.version(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 20, in version
return getattr(self.versioner, 'version')(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 37, in version
buf = self.concatenate(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 27, in concatenate
return '\n'.join([self.read_file(path) for path in paths])
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 31, in read_file
file = storage.open(path, 'rb')
File "/my/virtual/env/lib/python2.7/site-packages/django/core/files/storage.py", line 33, in open
file = self._open(name, mode)
File "/my/virtual/env/lib/python2.7/site-packages/storages/backends/s3boto.py", line 177, in _open
raise IOError('File does not exist: %s' % name)
IOError: File does not exist: css/style.css
which is one of my source files. So why does pipeline no longer want to do the filter/concatenate/compress steps when I switch to s3boto storage?
It may be that I'm doing something. Here is other config in case it helps:
INSTALLED_APPS = (
...
'pipeline',
'storages',
)
STATICFILES_FINDERS = (
'pipeline.finders.PipelineFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = "/some/path/outside/django_project/deploy_static"
STATICFILES_DIRS = () # All statics in this site are in apps
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
PIPELINE = True
PIPELINE_AUTO = True
PIPELINE_VERSION = True
PIPELINE_VERSION_PLACEHOLDER = 'VERSION'
PIPELINE_VERSIONING = 'pipeline.versioning.hash.SHA1Versioning'
PIPELINE_CSS = {
'standard': {
'source_filenames': (
'css/style.css',
...
),
'output_filename': 'css/all-VERSION.css',
'extra_context': {
'media': 'screen,projection',
},
}
}
My site is on Django 1.3.1.
The command I'm running is:
python manage.py synccompress --force
The AWS creds are also in settings, but that's moot because it's not even getting to that point.
UPDATE Added full stack and settings requested in comments
UPDATE At the request of the library author, I tried upgrading to the latest beta. Observations from that so far:
I don't know how to get versioned compressed files now
collectstatic leaves me with the compressed files and the originals
Still getting the same error from django-pipeline when boto storage is configured: it wants to send my source files to s3, but I can't even see where it's staging my assets. Nothing gets placed in STATIC_ROOT.
UPDATE I've created the simplest project that works for finder storage and then breaks with S3Boto. I've pushed it to github, and included a capture of the stacktrace.
https://github.com/estebistec/simple_pipeline
https://raw.github.com/estebistec/simple_pipeline/master/STACKTRACE
I would be ecstatic if I could be told I'm doing some really dumb and this should all just work.
django-pipeline 1.1.x is a bit dumb about how you should use staticfiles, it prefers to have everything in one place.
I suggest you to try django-pipeline 1.2 with latest django-staticfiles or django 1.4.
Use a custom like this :
STATICFILES_STORAGE = 'your.app.S3PipelineStorage'
The code looks like this :
from staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
You can find how to fix your application, but there is still a bug with compiled files unless you use version 1.2c1 : https://gist.github.com/1999564
I just experienced this same error on a Django 1.6 project with django-pipeline==1.3.23, and the solution was simply removing the PIPELINE_STORAGE setting.
There is another problem with similar error message that affects earlier and current version (1.5.4) of django-pipeline.
The error message is IOError: File does not exist, and it happens in s3boto.py.open() and packager.pack_stylesheets(). You might hit the problem if you use any of the compiler (Compass, Sass, Less etc). I suspect it would also affect JS compiler, but I have not confirmed.
In a nutshell, the compiler generates output file in the local static storage and the next steps, compress is trying to find the output in s3 storage.
If it affects you, you might want to take a look at https://github.com/cyberdelia/django-pipeline/issues/473. There are two pull-requests (patches), one made by skirsdeda and another made by thomasyip (me). Both might solve your problem. If you would like the compiled (but, pre-compressed) file to be copied to s3 and available to the app, the you would take thomasyip (me)'s patch.
Here is full Traceback for the problem:
Traceback (most recent call last):
File "apps/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 171, in handle_noargs
collected = self.collect()
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 117, in collect
for original_path, processed_path, processed in processor:
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/storage.py", line 26, in post_process
packager.pack_stylesheets(package)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/packager.py", line 96, in pack_stylesheets
variant=package.variant, **kwargs)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/packager.py", line 106, in pack
content = compress(paths, **kwargs)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 73, in compress_css
css = self.concatenate_and_rewrite(paths, output_filename, variant)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 137, in concatenate_and_rewrite
content = self.read_text(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 220, in read_text
content = self.read_bytes(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 214, in read_bytes
file = staticfiles_storage.open(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 35, in open
return self._open(name, mode)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/storages/backends/s3boto.py", line 366, in _open
raise IOError('File does not exist: %s' % name)
IOError: File does not exist: sheets/sass/sheets.css
Complementing the answers, you could use GZIP as well when compressing:
from django.contrib.staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
def __init__(self, *args, **kwargs):
self.gzip = True
super(S3PipelineStorage, self).__init__(*args, **kwargs)
Using the settings as follows:
COMPRESS_STORAGE = STATICFILES_STORAGE = 'my.apps.main.S3PipelineStorage'
Not sure how this seemed to work for everyone else. I followed the solution above and kept getting the following error:
Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
collected = self.collect()
File "python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
for original_path, processed_path, processed in processor:
File "python3.4/site-packages/pipeline/storage.py", line 26, in post_process
packager.pack_stylesheets(package)
File "python3.4/site-packages/pipeline/packager.py", line 96, in pack_stylesheets
variant=package.variant, **kwargs)
File "python3.4/site-packages/pipeline/packager.py", line 105, in pack
paths = self.compile(package.paths, force=True)
File "python3.4/site-packages/pipeline/packager.py", line 99, in compile
return self.compiler.compile(paths, force=force)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 56, in compile
return list(executor.map(_compile, paths))
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 549, in result_iterator
yield future.result()
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 402, in result
return self.__get_result()
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 354, in __get_result
raise self._exception
File "/usr/local/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 42, in _compile
outdated = compiler.is_outdated(input_path, output_path)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 85, in is_outdated
return self.storage.modified_time(infile) > self.storage.modified_time(outfile)
File "python3.4/site-packages/storages/backends/s3boto.py", line 480, in modified_time
return parse_ts(entry.last_modified)
AttributeError: 'NoneType' object has no attribute 'last_modified'
It wasn't until I came across this solution that I started to find what worked for me. Here's the storage that I ended up using that saved the file locally as well as in S3 which got me passed all errors:
from django.contrib.staticfiles.storage import ManifestFilesMixin
from django.core.files.storage import get_storage_class
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(PipelineMixin, ManifestFilesMixin, S3BotoStorage):
"""Custom storage for static content."""
def __init__(self, *args, **kwargs):
super(StaticStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
'django.contrib.staticfiles.storage.StaticFilesStorage')()
def save(self, name, content):
name = super(StaticStorage, self).save(name, content)
self.local_storage._save(name, content)
return name

Categories

Resources