简体   繁体   English

Python请求+ Azure VM

[英]Python Requests + Azure VM

I'm using python requests library to talk between two of my apps (django and ckan) inside Azure VM (clean ubuntu 12.04). 我正在使用python请求库在Azure VM(干净的ubuntu 12.04)中的两个应用程序(django和ckan)之间进行通信。

And very wired bug appears. 并且出现了非常有线的错误。 It seems like request.post sent successfully, but on the middle of my code running I got 504 request timeout . 似乎request.post发送成功,但是在运行代码的中间,我收到了504 request timeout

Apache2, Nginx and Gunicorn (only timeout appears) logs are clean. Apache2,Nginx和Gunicorn(仅出现超时)日志是干净的。 My CKAN app throws same error but with different ports: 我的CKAN应用抛出相同的错误,但端口不同:

CKAN error example 1: CKAN错误示例1:

Exception happened during processing of request from ('127.0.0.1', 53555)
Traceback (most recent call last):
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

CKAN error example 2: CKAN错误示例2:

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53344)
Traceback (most recent call last):
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

As you can see port Is always different. 如您所见,端口始终是不同的。 One of my thoughts -- Azure has all ports closed unless you specify which one you want to open. 我的想法之一-Azure会关闭所有端口,除非您指定要打开哪个端口。

I have same codebase working alright locally. 我在本地也可以使用相同的代码库。

By default, Azure linux VMs disable all ports except 22 to prevent inbound requests from internet. 默认情况下,Azure linux VM禁用除22外的所有端口,以阻止来自Internet的入站请求。 you can try to specify your Django app's port and configure the endpoint of the other VM with ckan. 您可以尝试指定Django应用程序的端口,并使用ckan配置其他VM的端点。

Also, you can refer to https://github.com/Azure/azure-content/blob/master/articles/virtual-machines/virtual-machines-python-django-web-app-linux.md to deploy your django app on apache and bind it on 80 port on your VM. 另外,您可以参考https://github.com/Azure/azure-content/blob/master/articles/virtual-machines/virtual-machines-python-django-web-app-linux.md来部署django应用在apache上并将其绑定到VM的80端口上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM