http request inside gunicorn causes gunicorn response to fail?

旧时模样 提交于 2019-12-12 02:46:31

问题


I'm running the below code slightly modfied from gunicorn's website (http://gunicorn.org/run.html)

import urllib2

def app(environ, start_response):
    print "in app"
#    response=urllib2.urlopen('http://www.google.com')
    data = 'Hello, World!\n'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response('200 OK', response_headers)
    print "    starting response"
    return iter([data])

It runs completely as expected except when I uncomment the urrllib2.urlopen line, the entire code fails silently.

I'm running gunicorn with no conf file specified, meaning errors should be written to stdout (there aren't any). The browser making the request to gunicorn errors and claims "No date received"

Any idea what's going? I haven't found anything even remotely related to this elsewhere on the web.

Thanks!


回答1:


I figured this one out by looking here: https://github.com/benoitc/gunicorn/issues/38

which pointed me to this documented bug in urllib2 on OS X - https://trac.macports.org/ticket/24421

I managed to fix it by using python 2.6.6 instead of python 2.6.5 - pretty sure I installed them differently as well which could have also been the fix. Another of the suggested fixes was to downgrade python to 2.6.4



来源:https://stackoverflow.com/questions/7918378/http-request-inside-gunicorn-causes-gunicorn-response-to-fail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!