oTree Forum >

MTurk sandbox error

#1 by Scott

Hi there, trying to deploy to MTurk, but get the error below when trying to Publish HIT to sandbox:

WSL Ubuntu: 22.04
otree: 5.10.1 (Installed otree[mturk])
python: 3.9.15


Exception in ASGI application
Traceback (most recent call last):
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/otree/mturk_client.py", line 144, in call_api
    resp = urlopen(request, data=request_body)
  File "/usr/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/usr/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 396, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/otree/views/mturk.py", line 133, in post
    hit = TurkClient.create_hit(mturk_hit_parameters, use_sandbox=use_sandbox)[
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/otree/mturk_client.py", line 167, in create_hit
    return call_api('CreateHIT', request_params, use_sandbox=use_sandbox)
  File "/mnt/d/venv/otree5p9/lib/python3.9/site-packages/otree/mturk_client.py", line 146, in call_api
    msg = json.loads(exc.read().decode('utf8'))['Message']
KeyError: 'Messag

Any ideas?

#2 by Chris_oTree

Can you put a print statement in this file:


Before that line in the traceback, put:


What is the output?

#3 by Scott

Hi Chris, this is the output:

{"__type":"UnrecognizedClientException","message":"The security token included in the request is invalid."}

I guess this points to invalid AWS keys - I made a couple up for testing. My keys are:


The key creation instructions here: https://otree.readthedocs.io/en/latest/mturk.html#local-sandbox-testing look very different to the ones on the current AWS site, and the link to the AWS site no longer works.

I couldn't figure out how to generate them using the AWS Certificate Manager. Any pointers would be much appreciated.


#4 by Scott

... Sorry, I meant the Key Manager Service (Not ACM)

Write a reply

Set forum username