rorodata / firefly

function as a service
http://rorodata.github.io/firefly
Apache License 2.0
194 stars 30 forks source link

Error returning a file #62

Closed palnabarun closed 7 years ago

palnabarun commented 7 years ago

Returning a file from a function is giving the following error:

$ firefly funcs.rf
2017-09-05 01:51:01 firefly [INFO] Starting Firefly...
http://127.0.0.1:8000/
127.0.0.1 - - [05/Sep/2017 01:51:07] "GET / HTTP/1.1" 200 263
127.0.0.1 - - [05/Sep/2017 01:51:07] "POST /rf HTTP/1.1" 200 0
Traceback (most recent call last):
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
127.0.0.1 - - [05/Sep/2017 01:51:07] "POST /rf HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 36168)
Traceback (most recent call last):
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 141, in run
    self.handle_error()
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 368, in handle_error
    self.finish_response()
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 138, in handle
    handler.run(self.server.get_app())
  File "/usr/lib/python3.5/wsgiref/handlers.py", line 144, in run
    self.close()
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 36, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
# funcs.py
def rf():
    f = open('firefly.yml', 'r')
    return f
palnabarun commented 7 years ago

Since, firefly supports sending files opened in binary mode, the above issue is redundant.

Also, file support should be added as an example in the documentation. I will create another issue for the same.