I am trying Oxygen.jl . Not working:
using Oxygen, HTTP
function start_server()
@get "/greet" function(req::HTTP.Request)
return "hello world!"
end
# start the web server
serve()
end
start_server()
Client:
In [1]: %run simulate_http.py
---------------------------------------------------------------------------
gaierror Traceback (most recent call last)
~/repos/pykitesim/simulate_http.py in <module>
4 connection = http.client.HTTPConnection('http://127.0.0.1:8080')
5
----> 6 connection.request('GET', '/greet')
7
8 response = connection.getresponse()
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in request(self, method, url, body, headers, encode_chunked)
1254 encode_chunked=False):
1255 """Send a complete request to the server."""
-> 1256 self._send_request(method, url, body, headers, encode_chunked)
1257
1258 def _send_request(self, method, url, body, headers, encode_chunked):
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1300 # default charset of iso-8859-1.
1301 body = _encode(body, 'body')
-> 1302 self.endheaders(body, encode_chunked=encode_chunked)
1303
1304 def getresponse(self):
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in endheaders(self, message_body, encode_chunked)
1249 else:
1250 raise CannotSendHeader()
-> 1251 self._send_output(message_body, encode_chunked=encode_chunked)
1252
1253 def request(self, method, url, body=None, headers={}, *,
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in _send_output(self, message_body, encode_chunked)
1009 msg = b"\r\n".join(self._buffer)
1010 del self._buffer[:]
-> 1011 self.send(msg)
1012
1013 if message_body is not None:
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in send(self, data)
949 if self.sock is None:
950 if self.auto_open:
--> 951 self.connect()
952 else:
953 raise NotConnected()
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/http/client.py in connect(self)
920 def connect(self):
921 """Connect to the host and port specified in __init__."""
--> 922 self.sock = self._create_connection(
923 (self.host,self.port), self.timeout, self.source_address)
924 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/socket.py in create_connection(address, timeout, source_address)
785 host, port = address
786 err = None
--> 787 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
788 af, socktype, proto, canonname, sa = res
789 sock = None
~/repos/pykitesim/.pixi/envs/default/lib/python3.8/socket.py in getaddrinfo(host, port, family, type, proto, flags)
916 # and socket type values to enum constants.
917 addrlist = []
--> 918 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
919 af, socktype, proto, canonname, sa = res
920 addrlist.append((_intenum_converter(af, AddressFamily),
gaierror: [Errno -2] Name or service not known
In [2]:
Any idea?
In the browser this URL works:
http://127.0.0.1:8080/greet