TypeError: '<=' not supported between instances of 'int' and 'bytes'

693 views
Skip to first unread message

moul...@gmail.com

unread,
Dec 4, 2021, 6:20:48 PM12/4/21
to oTree help & discussion
Hi,

I am getting this error when I am starting a participant in demo.

This is the traceback:

Exception in ASGI application
Traceback (most recent call last):
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 26, in __call__
    await response(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\responses.py", line 224, in __call__
    await run_until_first_complete(
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\concurrency.py", line 24, in run_until_first_complete
    [task.result() for task in done]
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\concurrency.py", line 24, in <listcomp>
    [task.result() for task in done]
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\responses.py", line 216, in stream_response
    async for chunk in self.body_iterator:
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 56, in body_stream
    task.result()
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 38, in coro
    await self.app(scope, receive, send)
  File "c:\programdata\anaconda3\lib\site-packages\otree\errorpage.py", line 247, in __call__
    raise exc  # from None
  File "c:\programdata\anaconda3\lib\site-packages\otree\errorpage.py", line 227, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 25, in __call__
    response = await self.dispatch_func(request, self.call_next)
  File "c:\programdata\anaconda3\lib\site-packages\otree\middleware.py", line 42, in dispatch
    response = await call_next(request)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 45, in call_next
    task.result()
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\base.py", line 38, in coro
    await self.app(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\middleware\sessions.py", line 75, in __call__
    await self.app(scope, receive, send_wrapper)
  File "c:\programdata\anaconda3\lib\site-packages\otree\patch.py", line 41, in __call__
    raise exc  # from None
  File "c:\programdata\anaconda3\lib\site-packages\otree\patch.py", line 29, in __call__
    await self.app(scope, receive, sender)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\routing.py", line 582, in __call__
    await route.handle(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\routing.py", line 243, in handle
    await self.app(scope, receive, send)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\endpoints.py", line 32, in dispatch
    response = await run_in_threadpool(handler, request)
  File "C:\Users\mouli\AppData\Roaming\Python\Python38\site-packages\starlette\concurrency.py", line 40, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "c:\programdata\anaconda3\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "c:\programdata\anaconda3\lib\site-packages\otree\views\participant.py", line 76, in get
    first_url = pp._url_i_should_be_on()
  File "c:\programdata\anaconda3\lib\site-packages\otree\models\participant.py", line 128, in _url_i_should_be_on
    if self._index_in_pages <= self._max_page_index:
TypeError: '<=' not supported between instances of 'int' and 'bytes'

I do not know how to solve this. 

Can someone please help?

Thank you,
Mouli.

Chris @ oTree

unread,
Dec 4, 2021, 6:31:33 PM12/4/21
to oTree help & discussion
Hi, firstly check that your code does not contain anything about _max_page_index (that is an internal attribute and it should not be used).

Otherwise, you could send me your project and tell me the instructions to reproduce this error. Also what version of oTree is this?

This is quite an unusual type of error...

Chris @ oTree

unread,
Dec 4, 2021, 6:32:38 PM12/4/21
to oTree help & discussion
By the way in your other message you said you are upgrading from oTree 3 to 5, so if you want to send me the project I can try to update it to ensure it is oTree 5 compatible.

moul...@gmail.com

unread,
Dec 4, 2021, 6:45:25 PM12/4/21
to oTree help & discussion
Hi,

I have sent you the code from (modakm@*******.edu). And I tried to make the code oTree 5 compatible using all the new documentation. I might have made some mistakes.

Thank you,
Mouli.

Chris @ oTree

unread,
Dec 4, 2021, 7:12:09 PM12/4/21
to oTree help & discussion
I took a look and the cause of the error is basically this line that uses numpy:

num_rounds = np.cumsum(SGLengths)

You should convert it to an int:

num_rounds = int(np.cumsum(SGLengths))

It's a sneaky error because numpy integers look and behave like regular integers, but their underlying data is different and they get stored to the database differently. oTree has some code to automatically convert numpy values to regular integers, but it can't catch all cases, like this one.

Anyway I am makin some other changes to your code and will send you.

Chris @ oTree

unread,
Dec 4, 2021, 7:13:55 PM12/4/21
to oTree help & discussion
Actually to be more accurate it's this:

SGEndPeriods = np.cumsum(SGLengths)
num_rounds = SGEndPeriods[-1] + 1

moul...@gmail.com

unread,
Dec 4, 2021, 7:37:43 PM12/4/21
to oTree help & discussion
Hi,

Thank you so much. I am getting more errors after fixing what you mentioned. 

For example, 

{{ block app_styles }}
    {{ include 'CSS_details.html' }}
{{ endblock }}

is giving an error of "Loader cannot locate the template file 'CSS_details.html'".

Mouli.

Reply all
Reply to author
Forward
0 new messages