oTree Forum >

<Response [403]> HTTP Request Header otree-rest-key is missing

#1 by Raphael

Hello everyone,
I would like to activate browser bots on my Heroku server using my command-line browser. I have already created a value called OTREE_REST_KEY on my Heroku server under 'Settings' -> 'Config Vars' -> 'Reveal Config Vars'.

With the help of this Python file, I am able to create a room on my Heroku server:
__________________________________________________________________________________
import requests
from pprint import pprint

GET = requests.get
POST = requests.post

SERVER_URL = 'https://exampleserver.herokuapp.com'
REST_KEY = 'ExampleKey'

def call_api(method, *path_parts, **params) -> dict:
path_parts = '/'.join(path_parts)
url = f'{SERVER_URL}/api/{path_parts}/'
resp = method(url, json=params, headers={'otree-rest-key': REST_KEY})
if not resp.ok:
msg = (
f'Request to "{url}" failed '
f'with status code {resp.status_code}: {resp.text}'
)
raise Exception(msg)
return resp.json()

data = call_api(
POST,
'sessions',
session_config_name='ExampleName',
room_name='ExampleRoom',
num_participants=4,
modified_session_config_fields=dict(use_browser_bots=True),
)
pprint(data)
__________________________________________________________________________________

I have created an environment variable within my PyCharm project that matches the Heroku OTREE_REST_KEY variable.

When I try to test the browser bots with this command:
otree browser_bots ExampleName --server-url=https://exampleserver.herokuapp.com

I receive this error message:
AssertionError: Request to close the existing browser bots session failed. Response: <Response [403]> HTTP Request Header otree-rest-key is missing.

Unfortunately, I'm not sure what I'm overlooking. Can you please help me with this? Thank you very much!
(Of course, the example values have been replaced by me to ensure that I do not disclose my actual data publicly.)

Write a reply

Set forum username