```{'version': '2.0', 'routeKey': 'GET /', 'rawPat...
# help
j
Copy code
{'version': '2.0', 'routeKey': 'GET /', 'rawPath': '/', 'rawQueryString': '', 'headers': {'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'accept-encoding': 'gzip, deflate, br', 'accept-language': 'nl-NL,nl;q=0.9,en-NL;q=0.8,en;q=0.7,en-US;q=0.6,fr;q=0.5', 'cache-control': 'max-age=0', 'content-length': '0', 'dnt': '1', 'host': '<http://l7m9q9ic8f.execute-api.us-east-1.amazonaws.com|l7m9q9ic8f.execute-api.us-east-1.amazonaws.com>', 'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"', 'sec-ch-ua-mobile': '?0', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'none', 'sec-fetch-user': '?1', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36', 'x-amzn-trace-id': 'Root=1-6139c317-73c82b1e16bbe783588a6ded', 'x-forwarded-for': '82.170.147.5', 'x-forwarded-port': '443', 'x-forwarded-proto': 'https'}, 'requestContext': {'accountId': '915964404932', 'apiId': 'l7m9q9ic8f', 'domainName': '<http://l7m9q9ic8f.execute-api.us-east-1.amazonaws.com|l7m9q9ic8f.execute-api.us-east-1.amazonaws.com>', 'domainPrefix': 'l7m9q9ic8f', 'http': {'method': 'GET', 'path': '/', 'protocol': 'HTTP/1.1', 'sourceIp': '82.170.147.5', 'userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'}, 'requestId': 'FYtrwjaDoAMEJkw=', 'routeKey': 'GET /', 'stage': '$default', 'time': '09/Sep/2021:08:17:27 +0000', 'timeEpoch': 1631175447808}, 'isBase64Encoded': False}
SyntaxError: Unexpected token n in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError (/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/body-parser/lib/types/json.js:158:10)
    at parse (/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/body-parser/lib/types/json.js:83:15)
    at /home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/body-parser/lib/read.js:121:18
    at invokeCallback (/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/raw-body/index.js:224:16)
    at done (/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/raw-body/index.js:273:7)
    at IncomingMessage.emit (events.js:412:35)
    at IncomingMessage.emit (domain.js:470:12)
    at endReadableNT (internal/streams/readable.js:1317:12)
Traceback (most recent call last):
  File "/home/jobdenoo/dearhealth/services/poc-sst/my-sst-app/node_modules/@serverless-stack/cli/scripts/util/bootstrap.py", line 99, in <module>
    r = request.urlopen(req, data=data)
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
c725cef9-e66c-4ffb-bc5c-5bad18ff538f ERROR Runtime exited with error: exit status 1
a
@Job de Noo this is most probably not related to sst. It seems like you are getting a non JSON response from your endpoint. Are you getting a proper response with cURL or postman? or if that's a get request you should be able to check that in the browser too
j
so end point should always return json?
a
depending on your setup but in this case it seems like there is something trying to parse that response as a JSON string
Copy code
SyntaxError: Unexpected token n in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError
j
the method is just printing the event
if i return a dict with {'statusCode' : 200} it fails as wel because it says a set is not serializabe
a
Copy code
urllib.error.HTTPError: HTTP Error 400: Bad Request
c725cef9-e66c-4ffb-bc5c-5bad18ff538f ERROR Runtime exited with error: exit status 1
you also have this which means in general that you are missing some arguments
j
// Create a HTTP API     const api = new sst.Api(this, "Api", {       defaultFunctionProps: {         srcPath: "src",         runtime: "python3.8"       },       routes: {         "GET /": "handler.handle",       },     });     // Show the endpoint in the output     this.addOutputs({       "ApiEndpoint": api.url,     });
it should just handle a get on / right?
a
what does your function body look like?
j
def handle(event, context):     return json.dumps({'statusCode', 200})
i tried this
this return {'statusCode', 200}return {'statusCode', 200}
and just not returning anything
all valid responses for api gateway
a
Copy code
import json

def handle(event, context):
    return json.dumps(event, indent=2)
can you try this?
j
same issue
a
sorry had a mistake there it should be
Copy code
from __future__ import print_function
import json

def handle(event, context):
    print(json.dumps(event, indent=2))
j
prints the event but then fails
a
APIGatewayEvent
has a
body
property which is already a JSON string so something like this might work for you
Copy code
import json

def handle(event, context):
    return event.body
j
with same error
a
I'm not entirely sure how to do that in python ))
also make sure you have proper permissions set for your function in your stack file
j
there shouldn't be any permissions right?
but sst can't support all cases api gateway supports?
a
not sure
look at the docs if you haven't already https://docs.serverless-stack.com/constructs/ApiGatewayV1Api and also try cloning and running this https://github.com/serverless-stack/serverless-stack/tree/master/examples/rest-api if it works for you then there something with the python function
j
this function can be deployed with cdk or serverless without issues
so don't think it is
return {'statusCode': 200 }
now works
don't understand why, earlier it did not
f
@Aram thanks for look into issue.
Hey @Job de Noo did you manage to resolve the issue?
a
@Job de Noo I think you were doing
Copy code
return json.dumps({'statusCode', 200})
wrapping it with json.dumps, maybe that's why?