LoginSignup
0
0

More than 5 years have passed since last update.

Azureで簡易APIを作る時のsocket.error

Last updated at Posted at 2018-03-19

サクッと行くと思ってたところ、
ちょっとハマったのでメモ。
簡易APIを作ろうとしてたところ、下記のエラーが出て困ってた。

sample.py
# -*- coding:utf-8 -*-
import json
import falcon

class HelloResource(object):
    # getされた時の動作
    def on_get(self, req, res):
        msg = {
            "message": "Welcome to the Falcon"
        }
        res.body = json.dumps(msg)
app = falcon.API()
app.add_route("/", HelloResource())

if __name__ == "__main__":
    from wsgiref import simple_server
    httpd = simple_server.make_server("104.215.000.000", 8080, app)
    httpd.serve_forever()

Traceback (most recent call last):
  File "sample.py", line 17, in <module>
    httpd = simple_server.make_server("104.215.000.000", 8080, app)
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 151, in make_server
    server = server_class((host, port), handler_class)
  File "/usr/lib/python2.7/SocketServer.py", line 417, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 48, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 99] Cannot assign requested address

他のサーバーやと通るのにazureで通らないぞ。。。

portを開ける

どうせポートが空いてないんじゃないと思って、
この辺を見ながらポートを開ける。
http://www.rarpa.net/?p=5422

bindする?

これを叩いたら見事動いた。

gunicorn sample:app --bind 0.0.0.0:8080

{"message": "Welcome to the Falcon"}

iptableかなんかでローカルのどっかでフィルターかかっちゃってるのかな。。。
後々調べようと思う。
一旦は動いた。

参考
https://stackoverflow.com/questions/29345898/invalid-address-when-startup-gunicorn
https://stackoverflow.com/questions/20858844/using-gunicorn-to-run-app-error/34567435

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0