Django 和 fcgi 和 mod_fcgid 错误

发布于 2024-12-22 06:08:07 字数 4756 浏览 3 评论 0原文

好吧,我对 Bluehost 的共享服务器上的这个问题感到筋疲力尽,但我找不到任何想法。


我已经上传了我的应用程序,除了我正在使用的照片上传器(这是该网站的核心)之外,一切似乎都工作正常。我正在使用 stdimage2 Django 应用程序(stdimage 的一个分支),它在开发服务器(Ubuntu 10.04)上运行良好。但目前它遇到了重大问题,我正在寻找任何可能的想法或我所缺少的事情的线索。

这是打印出来的错误(上传者将四张图片作为单独的请求一个接一个地发送): 这就是

[Wed Dec 21 09:47:03 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [warn] RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored.
[Wed Dec 21 09:47:03 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:04 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:04 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:05 2011] [error] mod_fcgid: process /home3/fernsten/public_html/ffamily/gallery/mySite.fcgi(22492) exit(communication error), get unexpected signal 11

我的 fcgi 文件的样子:

#!/home3/fernsten/local/Python-2.7/bin/python
import sys, os
print "sys.path is ", sys.path

#add a custom Python path and pray it works dddd
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages/flup-1.0.2-py2.7.egg")
sys.path.insert(0, "/home3/fernsten/django_projects")
sys.path.insert(0, "/home3/fernsten/django_projects/gallery")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages/MySQL_python-1.2.3-   py2.7-linux-x86_64.egg")

os.chdir("/home3/fernsten/django_projects/gallery")

os.environ['DJANGO_SETTINGS_MODULE'] = "gallery.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

最后,这是它死掉的函数:

if request.method == 'POST':
    result = []
    newform = Photo()
    newform.image= request.FILES.get('file')
    newform.album=Album.objects.get(pk=album_pk)
    newform.save()
    result.append({"name":"Uploaded image",
                    "size":newform.image.size,
                    "url":MEDIA_URL + newform.image.url,
                    "thumbnail_url": newform.image.url.replace(".",".thumbnail."),
                    "delete_url":'/backend/delete_img/' + str(newform.pk)+'/',
                    "delete_type":"POST",
                    })
    response_data = simplejson.dumps(result)
    return HttpResponse(response_data, mimetype='application/json')
return render_to_response('backend/upload_images.html',{'album_pk':album_pk},context_instance=RequestContext(request))

我相当确定它发生在这个区域,因为当我执行 newform.save() stdimage2 时,stdimage2 会在后台执行操作,例如重命名上传的图片以及创建和命名缩略图。正在重命名图像,但未生成缩略图。

任何想法都会很棒,因为我还没有找到太多可能出错的地方。


更新

我也无法使用 Django 中的管理界面上传图像。好吧,我可以上传图像,但那时它就坏了。 StdImage2 根据模型定义更改上传的图像名称,但不创建缩略图。在数据库中,它使用上传的图像名称(而不是生成的图像名称)存储图像的 URL。

为了涵盖所有基础,我从服务器复制了文件并在本地运行,没有任何问题。这只会造成更多的混乱和沮丧。


更新 2

使用 Django shell 并尝试这种方式后(至少我希望我做得正确)我收到以下错误:

image = Image.open('/home3/fernsten/www/ffamily/media/media/albums/1/image_1.jpeg')
>>> newform.image = image
>>> newform.album = Album.objects.get(pk=1)
>>> newform.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/base.py", line 460, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/base.py", line 543, in save_base for f in meta.local_fields if not isinstance(f, AutoField)]
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 253, in pre_save
if file and not file._committed:
File "/home3/fernsten/local/lib/python2.7/site-packages/PIL/Image.py", line 512, in   __getattr__
raise AttributeError(name)
AttributeError: _committed

Ok I'm exhausted with this problem on my shared server at Bluehost and I haven't been able to find any ideas.


I've uploaded my app and everything appears to be working fine except for one thing, the photo uploader that I'm using (which is the core of the site). I'm using the stdimage2 Django app (a fork of stdimage) and it worked fine on the development server (Ubuntu 10.04). But it's having major problems at the moment and I'm looking for any possible ideas or inklings of things that I'm missing.

Here's the errors that are being printed out (this is with four pictures being sent as separate requests one after the other by the uploader):

[Wed Dec 21 09:47:03 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [warn] RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored.
[Wed Dec 21 09:47:03 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:03 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:04 2011] [warn] [client 128.187.97.6] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:04 2011] [error] [client 128.187.97.6] Premature end of script headers: mySite.fcgi, referer: http://gallery.fernstenfamily.com/backend/upload/1/
[Wed Dec 21 09:47:05 2011] [error] mod_fcgid: process /home3/fernsten/public_html/ffamily/gallery/mySite.fcgi(22492) exit(communication error), get unexpected signal 11

This is what my fcgi file looks like:

#!/home3/fernsten/local/Python-2.7/bin/python
import sys, os
print "sys.path is ", sys.path

#add a custom Python path and pray it works dddd
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages/flup-1.0.2-py2.7.egg")
sys.path.insert(0, "/home3/fernsten/django_projects")
sys.path.insert(0, "/home3/fernsten/django_projects/gallery")
sys.path.insert(0, "/home3/fernsten/local/lib/python2.7/site-packages/MySQL_python-1.2.3-   py2.7-linux-x86_64.egg")

os.chdir("/home3/fernsten/django_projects/gallery")

os.environ['DJANGO_SETTINGS_MODULE'] = "gallery.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

And lastly here's the function where it dies:

if request.method == 'POST':
    result = []
    newform = Photo()
    newform.image= request.FILES.get('file')
    newform.album=Album.objects.get(pk=album_pk)
    newform.save()
    result.append({"name":"Uploaded image",
                    "size":newform.image.size,
                    "url":MEDIA_URL + newform.image.url,
                    "thumbnail_url": newform.image.url.replace(".",".thumbnail."),
                    "delete_url":'/backend/delete_img/' + str(newform.pk)+'/',
                    "delete_type":"POST",
                    })
    response_data = simplejson.dumps(result)
    return HttpResponse(response_data, mimetype='application/json')
return render_to_response('backend/upload_images.html',{'album_pk':album_pk},context_instance=RequestContext(request))

I'm fairly certain it's happening in this area because when I do newform.save() stdimage2 does things in the background, such as renaming the uploaded picture and creating and naming a thumbnail. The image is being renamed but no thumbnail is being generated.

Any ideas would be awesome as I haven't been able to find much about what could be wrong.


UPDATE

I also cannot upload the image using the admin interface in Django. Well I can upload the image but it breaks at that point. StdImage2 changes the uploaded images name per the model definition but doesn't create the thumbnail. In the database it's storing the URL to the image with the uploaded image name, not the generated one.

To cover all my bases I copied the files from the server and ran it locally without any problems at all. Which has only caused more confusion and frustration.


UPDATE 2

After using the Django shell and trying it that way (at least I hope that I did it correctly I get the following error:

image = Image.open('/home3/fernsten/www/ffamily/media/media/albums/1/image_1.jpeg')
>>> newform.image = image
>>> newform.album = Album.objects.get(pk=1)
>>> newform.save()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/base.py", line 460, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/base.py", line 543, in save_base for f in meta.local_fields if not isinstance(f, AutoField)]
File "/home3/fernsten/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 253, in pre_save
if file and not file._committed:
File "/home3/fernsten/local/lib/python2.7/site-packages/PIL/Image.py", line 512, in   __getattr__
raise AttributeError(name)
AttributeError: _committed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-12-29 06:08:07

根据错误日志中的最后一行,某处似乎发生了分段错误。 Python 代码不应该发生这种情况,因此我首先查看 stdimage2 的代码,看看其中还有什么。

快速浏览一下源代码就会发现它也是 Python 的,并且它依赖的唯一外部库是 PIL。 PIL 是一个 C 库(至少是它的一部分),因此这可能就是发生错误的地方,特别是如果如您所说,字段被重命名,但未创建调整大小的图像。

PIL是如何安装在服务器上的?如果它是通过包管理器安装的,或者直接在服务器本身上编译的,那么可能需要更新它或重新编译。如果您从开发机器上复制了模块,那么那里可能会存在冲突(不同的库、不同的处理器架构等)。

我解决此问题的另一种方法是通过 python shell,而不是通过 Web 界面。尝试加载模型并触发似乎失败的 save() 。如果 shell 因分段错误而终止,请重试,但这次使用调试器进行单步执行。 (我实际上会在 StdImageField._resize_image 上放置一个 pdb 断点,然后运行代码直到遇到该断点。)

我认为没有更简单的方法来调试它;您的代码中似乎没有任何明显的东西会导致它,所以它看起来像是服务器本身上的东西。

There appears to be a segmentation fault occurring somewhere -- according to the last line in your error log. This shouldn't happen with Python code, so I'd start by looking at the code to stdimage2 to see what else is in there.

A quick perusal of the source suggests that it's all Python as well, and that the only external library that it depends on is PIL. PIL is a C library (at least part of it), so it's possible that that is where the error is occurring, especially if, as you say, the fields are renamed, but the resized images are not being created.

How was PIL installed on the server? If it was installed through a package manager, or compiled right on the server itself, then it might be necessary to update it, or recompile. If you copied the module from your development machine, then there may be a conflict there (different libraries, different processor architecture, etc.)

The other way I would go about troubleshooting this is from a python shell, rather than through the web interface. Try to load your model and trigger the save() that seems to be failing. If the shell terminates with a segmentation fault, then try it again, but this time single-stepping with a debugger. (I would actually put a pdb breakpoint on StdImageField._resize_image, and run the code until it hit that breakpoint.)

I don't think there's an easier way to debug this; there doesn't seem to be anything obvious in your code that would cause it, so it's looking like something on the server itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文