-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Random 'NoneType' object is not callable #795
Comments
Did you have to re-deploy for it to work again? Unfortunately, this is a really hard one to debug because there's no repro. My only thoughts are that it could be AWS fault or something to do with your IAM/account policies. |
Yes, re-deploying the code fixed it. I encountered this before, and I think another way I fixed it was by re-saving the function in the LAMBDA console. I could get it working again by adding a new ENV var and clicking Save. So it makes me think the lambda handler gets into some invalid state, and then is kept in that invalid state because the function is kept warm by the callback. By deploying or re-saving the function, AWS re-creates it and its ok again. Its hard to debug because I don't have a traceback, so i don't know where this is occuring in the code. I haven't seen this error when I used to run the webserver via EC2 instances. My guess is its happening in the zappa handler code? Do you have any recommendations on ways I could get some more logging in the lambda handler itself, to improve my chances of figuring out what is happening? |
@Miserlou so that it looks like:
I see that the exec info is in the HTTP response when only settings.DEBUG is True, which makes sense. But can we add the traceback info to the logs as well? Since those are internal, it should be ok to add right? My site is on production, so settings.DEBUG is False, but I would still want access to the actual exception via the logs. |
It happened again today.
I have a theory. The Django CMS App I use has a thing called apphook reloads. When certain things about the site change the urls layout in Django, the Django CMS App forces a "server restart". I'm still investigating. |
Theory: "Packaging project as zip.." step is occasionally truncating files. I encountered this problem today. In my case the cause was the zipped-up app.py being truncated to 222 lines when it is supposed to be 270 lines. This causes "invalid syntax" once, and then "None Type Object is not callable" for subsequent calls. I discovered this by downloading the zipped up lambda code from aws console, unzipping and examining the app.py. Sure enough, it was truncated. A "zappa update"re-zipped and re-deployed the lambda function and all was fixed. I have encountered this error at least twice. I suspect some sort of race condition or missing file flush during the zip-up step. Log sample:
And then later: 'NoneType' object is not callable |
@darrell-rg However in my case, it happens without "zappa update". The code will be running fine on production, as packaged, then in a few days, I will encounter this error. |
I added this code after zipf.close() in https://github.com/Miserlou/Zappa/blob/master/zappa/core.py#L565. print("Verifying {} ..".format(zip_fname))
import zlib
with zipfile.ZipFile(zip_path, 'r') as zipf:
if zipf.testzip() is not None:
print("Zip File fails on {} ").format(zipf.testzip())
for i in zipf.infolist():
tpp = os.path.join(temp_project_path,i.filename)
if os.path.exists(tpp):
if os.path.getsize(tpp) != i.file_size:
print("ERROR DISK AND ZIP SIZES DO NOT MATCH: fn={} disksize={} zipsize={} ".format(i.filename,os.path.getsize(tpp),i.file_size))
with open(tpp, 'rb') as f:
crc = zlib.crc32(f.read()) & 0xffffffff
if crc != i.CRC:
print("ERROR DISK AND ZIP CRC DO NOT MATCH: fn={} diskCRC={} zipCRC={} ".format(i.filename,crc,i.CRC)) |
@darrell-rg If AWS is, they are doing it randomly, because it work in the beginning. It would say that must be a pretty remote chance tho. One suspicion is some type of naming conflig. My stuff uses the django rest framework, which defines its own "Response" object, which is different than the werkzeug Response object. I know that when django cms app forces a reload, it does some threading stuff and reloads all the sys.modules. I'm wondering if thats causing the werkzeug Response class to get replaced with the django rest framework version. I don't have a lot of understanding on how Python manages its imports, but I'm gonna try a few things and see what happens. The hard part is I haven't been able to reproduce this consistently. |
I stopped having this issue when I stopped using the slim_handler= true option. Not sure if this is it but I never experienced this issue for about a month until I started using the slim_handler, after that It happened about every day. |
@Miserlou Any update on this ? |
I am facing similar issues as well! It works fine on localhost but gives me the same error at a particular route. All the tables show up on the admin console every time ... I don't know what's wrong! |
Same problem. Did you find any solution? |
I too turned off slim_handler, and the issue hasn't happened again. |
I tried doing this with a new virtualenv and it works indeed. Thanks for the suggestion! |
@GeorgianaPetria Make sure your excluding any directories or files you don't need, like any build artifacts, node_modules, static/, vendor/, images, etc. Also remove any unneeded packages from your virtual environment |
I only have the zappa examples in my virtual env: https://github.com/Miserlou/Zappa/tree/master/example The biggest part of the env is importing scipy and sklearn and these two together make up for about 60M. I need them in order to deploy my machine learning model. Why is slim_handler = true not working? Unless I'm missing something, I don't think there's any chance I can get my zip under 50M. |
I'm also facing this issue when using the slim_handler option - reducing the package size is not looking easy. Like @bxm156 I am also running django rest framework. The app will run with no issues for a while and then, seemingly randomly, give up and throw the following error: After a while (potentially when that lambda node is replaced?) it will come back to life again. |
How to do you turn off slim_handler? |
@yamat124 in the zappa_settings.json file: For example:
|
@jasonrhaas Thanks for the response. I added that redeployed but I'm still getting the same error. I'm also using python 3.6.1 |
I'm facing the same problem as @GeorgianaPetria, any updates? |
Finally found the cause of my issue. A build script that ran before zappa included a sed command that did not flush the output buffer, which sometimes truncated my app.py file. If you are experiencing the variant of this issue that goes away when you re-deploy, check your build scripts for this sort of race condition. |
In my case, I don't have any build scripts
…On Sep 11, 2017 9:40 AM, "darrell-rg" ***@***.***> wrote:
Finally found the cause of my issue. A build script that ran before zappa
included a *sed* command that did not flush the output buffer, which
sometimes truncated my app.py file. If you are experiencing the variant of
this issue that goes away when you re-deploy, check your build scripts for
this sort of race condition.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#795 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAITZFMW2G_hlixTpmIE9FN3P4hXpiQhks5shWJmgaJpZM4NCABQ>
.
|
I found a cause for my problem with NoneType is not callable. I had pyc files between some of my source files that became part of zip. Deleting them and running zappa update solved my problem. I found error like this https://teamtreehouse.com/community/importerror-bad-magic-number-in-time-bx03xf3rn and it lead me to the pyc files. |
Would it be possible and safe to ignore .pyc files from source project directory? |
Not sure if this is related, but I ran into this issue and I resolved it by removing the cffi library from my python dependencies. I switched from flask-mikasa to flask-markdown and removed each extra dependency manually and redeployed each time. It looks like for my specific instance cffi was the culprit. |
Thank you @tista3, your solution was the one for me |
(this issue is the first on google for the NoneType exception) |
Just got the same error... I'm launching django projects in lambdas, not 1st time with this great project zappa :) |
I had the same problem. Just "Refreshing" my virtualenv solved the problem:
I decided to do that because I noticed that Zappa was packaging some modules that I clearly uninstalled before. So may be it's |
@dtnewman |
I am running inside a VPC, but I have a gateway setup and internet access seems to work fine. The curious thing is that this happens sporadically. I am certain that it is accessing the S3 files when I first deploy, because they are needed for setup and it seems to work just fine at first. But after anywhere from a few minutes to a few days later, an S3 access issue seems to arise somewhat randomly and then the system goes down (similar to original poster above) until I redeploy. EDIT: It seems like others are reporting that the problem happens when the |
@dtnewman in my experience, S3 more stable, than my solutions, and probably then yours :) |
But what happen if my package>50MB ? :( |
Fwiw: the 50mb limit is somewhat soft. I have uploaded packages as large as
60mb. I'm not sure what the real, enforced cut off is.
I adopted a microservice methodology, so I have multiple, small lambda
functions.
…On Mon, Jan 21, 2019, 1:09 PM coco-egaliciar ***@***.*** wrote:
I too turned off slim_handler, and the issue hasn't happened again.
But what happen if my package>50MB ? :(
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#795 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAITZAkagylqCy5J95GDFNqlJ0Y2-B0Pks5vFiyFgaJpZM4NCABQ>
.
|
You're also going to want to delete |
I'm hitting the same issue. Tried |
Someone who is looking for a solution this might help.
Hope this helps. |
I'm having the same problem. I first get it to work, then I add the dependencies sklearn numpy scipy and setting |
Same here, |
To everyone else here that might have some issues - by commenting one line at a time and uploading again and again, I've realized that an import statement in the top of the
I was able to find the actual issue in the dependent package, solve it, and upload my zappa function with no issues this time. I'm not sure why the import exception was not visible by zappa in the first place. BTW, the actual issue was in another package installing the |
For anyone else still having this issue, I was deploying just fine before setting I ultimately resolved the issue by running |
It seems i'm encountering the same problem as you. I am using |
@cmabastar I had control over the source code of the package that had the To make the |
Well I came across the issue lately and took time to investigate the problem. The issue is that lambda is timing out, at least for my case and I believe for many cases here too. Go over the logs in cloudwatch because unlike zappa tail logs, cloudwatch separate logs into logs from each container created by lambda as streams. I observed when a faulty container (one returning NoneType) diverged from the normal one. This is what happens. So once a request comes in and all the fired up containers are in use, a new container is created and during initialization, because we're downloading files from s3 to /tmp and also due to sometimes lagged connectivity + vpc/db initilializations, lambda doesn't always finish setting up within the default 30s lambda time_out set by zappa. Hence, the container times out and starts receiving request pre-maturely when in reality the modules have not all been imported. Hence the NoneType error. For every NoneType eror that I saw in cloudwatch, there was an import issue beforehand which confirms this. Therefore when new requests hit that container periodically, we see the NoneType. But when new request hit other containers without this issue, it works. And that explains for the periodic NoneType Error we get. Hence these are what you can do. If you can reduce the size of your code/dependencies please do so for two reasons
Now if you can't get your code base reduced to to the 250M unzipped / 50M zipped limit, maybe you're in case (2) above or can't even reduce anything at all, |
Hi, I've been struggling with this for the past 2 days, my 2 cents if it helps someone. My app was working locally but not on AWS In my case I had tried already setting slim_handler to false, deleted all the .pyc files, tried doing zappa update several times (yep, it worked in the past ¯_(ツ)_/¯ ), undeployed and deployed and nothing had worked so far. I started commenting imports in my In my case I'm reading env variables from a .env file. I found this and saw that the files where I was calling os.getenv where I hadn't called load_dotenv were failing, so I added
to each one of those files and that fixed it |
I tried all of these solutions and the last one I tried was blowing away my Trust me, try it, it takes a few minutes. This is with big packages like scikit learn, numpy, etc |
same happening here, seems like only happens when I attach vpc to the lambda, it get into a bad state and cannot read remote_env s3 files, I gave the permission full s3 permission still no luck |
This error can be caused by this SQLite problem: #1880 Please check zappa logs during deployment with |
not using sqlite at all, not sure if Django keep some reference for it somewhere |
I'm keeping this one open, because the damned message is not clear (and I hope to sort it out). I think I've fixed the problem with the "slim_handler: true" error handling that was causing corrupt files last year. Most other cases tend to fall into:
That's all I can think of at the moment. If you can replicate something outside or have an idea to make the information clearer, please share. |
In my case, the issue was caused by:
Solution: Increase These are the steps I took:
Thanks to @eexwhyzee for his comment prompting me in the right direction. |
Also getting this error. Deploying a flask application that uses boto3. Have a single POST route, slim_handler is Very frustrating. |
I am seeing issue without deploying. I am thinking its failing when its deploying the code to new containers. I don't have I have a keep_warm callback at 4 mins interval. I am not able to see the error in the Cloudwatch Logs. Any ideas ? |
I also got this error. In my case, I found I had a wrong import statement of a module after running |
Also getting this error deploying a flask application. |
I recently experienced this error today when updating some dependencies in requirements.txt for a Django application.
I wasn't able to find the exact package that was causing the issue, but I believe it was I've heard that using aws-psycopg2 can help. |
solution for me dont use sqlite as the db use another db like mysql or postgresql |
Randomly my site will go down (perhaps once or twice a month) and display the following:
{
"message": "An uncaught exception happened while servicing this request. You can investigate this with the
zappa tail
command."}
The logs say the following:
etc.
I don't see any further information in the logs that would be helpful. Is there a way I can get more detailed information about the error? It only happens about once a month or less. When it get into this state, the only thing I found has fixed the problem is redeploying the code.
Other side notes:
My Django project uses Amazon RDS. I can see in the graph that during this time, the DB connections goes to 0. And then back up once I have redeployed the code.
Possible Fix
Re-deploying my lambda code fixes the issue.
Steps to Reproduce
I haven't been able to reproduce it consistently, it just will happen randomly and won't be fixed until I redeploy my code.
Your Environment
My project is a Django 1.9 project, I'm not able to pos the code publicly though.
The text was updated successfully, but these errors were encountered: