2011-12-30 3 views
0

にhttp putリクエストを送信します.Werkzeugを使用してリクエストをリッスンして処理します。機能の1つでは、リクエスト(Aから)を聞き、別のサーバー(B)にHTTP putリクエストを送信する必要があります。その後、Bからの応答を取得した後、Aに応答します。ウェブアプリケーションでwerkzeug

私はwerkzeugに慣れておらず、要求を送信する能力があるかどうかもわからないので、要求を送信するためにhttplibを使用しました。

しかし、エラーが発生しています。

は、可動部分がたくさんありますが、私は次のよう疑問に思って: 。1. WERKZEUGは任意の助けに感謝エラー

の原因が何であるかを要求 2を送信する機能を持っています。

コード:

def complete(self, request): 
    if request.method == 'GET': 
     location_id = self.extract_param_value(request,'location_id'); 
     status_code = self.extract_param_value(request,'status_code'); 

     req_url = something; 
     jsonData = { 'data' : {'status' : status_code, 'id': location_id}}; 
     jsonDataDump = json.dumps(jsonData); 
     #send request to B 
     connection = httplib.HTTPConnection(HOST, timeout=5); 
     body_content = jsonDataDump; 
     headers = {"Content-type": "application/json", "Accept": "text/plain"}; 
     connection.request('PUT', req_url, body_content, headers); #error occurs here 
     result = connection.getresponse(); 
     connection.close(); 
     #return response to A 
     response = Response(status=200); 

     return response; 

エラー:カールと

 1**.1**.1**.** - - [30/Dec/2011 03:06:57] "GET //complete?location_id=615201308&status_code=LIVE&message=fine HTTP/1.1" 500 - 
     Traceback (most recent call last): 
     File "/home/ec2-user/y_ws.py", line 381, in __call__ 
     return self.wsgi_app(environ, start_response) 
     File "/usr/lib/python2.6/site-packages/Werkzeug-0.8.1-py2.6.egg/werkzeug/wsgi.py", line 411, in __call__ 
      return self.app(environ, start_response) 
      File "/home/ec2-user/y_ws.py", line 377, in wsgi_app 
      response = self.dispatch_request(request); 
      File "/home/ec2-user/y_ws.py", line 98, in dispatch_request 
      return getattr(self, endpoint)(request, **values) 
      File "/home/ec2-user/y_ws.py", line 184, in complete 
      connection.request('PUT', y_req_url, body_content, headers); 
      File "/usr/lib64/python2.6/httplib.py", line 914, in request 
      self._send_request(method, url, body, headers) 
      File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request 
      self.endheaders() 
      File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders 
      self._send_output() 
      File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output 
      self.send(msg) 
      File "/usr/lib64/python2.6/httplib.py", line 739, in send 
      self.connect() 
      File "/usr/lib64/python2.6/httplib.py", line 720, in connect 
      self.timeout) 
      File "/usr/lib64/python2.6/socket.py", line 567, in create_connection 
      raise error, msg 
     error: [Errno 111] Connection refused 

答えて

1
  1. WERKZEUGは、HTTPリクエストを作成するためのライブラリではありません、(あなたの例のように)httplibを使用
  2. チェックした場合要求がホストマシンから成功し、ネットワークの問題を排除します。取得しているエラーは一般的なネットワークエラーです。
関連する問題