WARNING: Invalid HTTP request received. Only when running GET request from inside of Excel

Ryan Godbey 6 Reputation points
2021-06-24T17:39:58.063+00:00

I am trying to write an Excel addin that uses node.js to make a GET request to a fastapi/uvicorn server on localhost. I am on MacOS Big Sur and the Current Channel(Preview) of Excel. Below is the function I wrote:

function getData() {
    //You can change this URL to any web request you want to work with.
    const http = require('http');
    const options = {
      hostname: 'localhost',
      port: 8000,
      path: '/1/2/3/4',
      method: 'GET'
    };

    const req = http.request(options, res => {
      res.on('data', d => {
        process.stdout.write(d)
      })
    })
    req.on('error', error => {
      console.error(error)
    })

    req.end()
}

If I run this in a terminal with node, it runs fine and shows a 200 response on the server. If I try running the function from within Excel as a UDF, it displays 0 in the cell and the server gives the following traceback:

WARNING:  Invalid HTTP request received.
Traceback (most recent call last):
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 172, in handle_events
    event = self.conn.next_event()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 443, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
    raise self
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 425, in next_event
    event = self._extract_next_receive_event()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
    event = self._reader(self._receive_buffer)
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_readers.py", line 72, in maybe_read_from_IDLE_client
    matches = validate(
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_util.py", line 88, in validate
    raise LocalProtocolError(msg)
h11._util.RemoteProtocolError: illegal request line: bytearray(b'\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\xb2vs;\xdaP\xfb[\x17o\xbb\x9d:>\x12@\xe2\xd8\xae\xfa5H\x0e\xac\xb9"d\xe8\x89\xd4No  \xb2\x98\xb5\xd9\xe5\x93?\xdeT\xbf\xa5Q\xf4\xac9\x19\x81?]\x05\x14\x1at\xf5\xca\xde\xbd\xea\xa2\xe7l\x008')
WARNING:  Invalid HTTP request received.
Traceback (most recent call last):
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 172, in handle_events
    event = self.conn.next_event()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 443, in next_event
    exc._reraise_as_remote_protocol_error()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_util.py", line 76, in _reraise_as_remote_protocol_error
    raise self
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 425, in next_event
    event = self._extract_next_receive_event()
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_connection.py", line 367, in _extract_next_receive_event
    event = self._reader(self._receive_buffer)
  File "/Users/rgodbey/Desktop/spade/venv/lib/python3.8/site-packages/h11/_readers.py", line 68, in maybe_read_from_IDLE_client
    raise LocalProtocolError("illegal request line")
h11._util.RemoteProtocolError: illegal request line

My thought is that somehow Excel is doing something to the GET request. Any help in debugging this is appreciated! Can I do something like console.log for excel?

Microsoft 365 and Office Development Other
0 comments No comments
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.