Forums

internal 500 server error

hello i have the next error in my aplication im reviwe all but it doesnt work

2023-04-29 22:25:07,232: Exception on /bot [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/LionsInv/mysite/main.py", line 20, in bot
    bot.Entrar(parametro)
  File "/home/LionsInv/mysite/FuturosBot.py", line 51, in Entrar
    pos = self.ObtenerPosicion(self.ticker)
  File "/home/LionsInv/mysite/FuturosBot.py", line 38, in ObtenerPosicion
    return c.ObtenerPosicion(ticker)
  File "/home/LionsInv/mysite/FuturosConsultas.py", line 39, in ObtenerPosicion
    pos = self.ObtenerPosiciones()
  File "/home/LionsInv/mysite/FuturosConsultas.py", line 33, in ObtenerPosiciones
    ac = self.ObtenerCuentaGeneral()
  File "/home/LionsInv/mysite/FuturosConsultas.py", line 26, in ObtenerCuentaGeneral
    parametros = "timestamp=" + str(self.ObtenerFechaServer())
  File "/home/LionsInv/mysite/Binance.py", line 22, in ObtenerFechaServer
    return resp["serverTime"]
KeyError: 'serverTime'

You need to check how does your response look like. It's probably something different then what your code expects.

thanks, check and arrive correct the data that has to arrive, also save it in a file created but when entering the method generates the error and I can not identify it

So does object resp which is processed by the code in file /home/LionsInv/mysite/Binance.py in line 22 have key "serverTime" now?

In the tests on my computer it works perfectly, it obtains and processes the data but when I upload it to pythonanywhere something happens and I get the error

for servertime import the following library; from datetime import datetime

resp["serverTime"] tries to access "serverTime" key on resp. You need to check how resp looks like in reality.

serverTime is a string that I get from a binance dictionary, this string shows me the time The whole application works when I run it before deployment but I upload it to pythonanywhere and it doesn't work

You need to look at the actual contents of the response that you're getting from binance.

when I run the application on my pc it generates the order perfectly and in real time it is done in binance but in pythonanywhere it generates error 500 I also try it with postman and in the same way it shows error 500, I have reviewed the code and everything seems to be correct

Have you checked the contents of the response from Binance? One thing that comes to mind is that they might be blocking access from PythonAnywhere due to some kind of geographic restrictions.

I created a file in flask where it received the data from binance and it received it correctly but when entering the application through the post method it does not allow me to continue, generating the error that I show at the beginning of the conversation. I still don't understand the source of the error

checking, i see this error Error running WSGI application 2023-05-04 16:18:53,846: ModuleNotFoundError: No module named 'serverTime'

Could you go into my files and review please? I give them all permissions

Have you checked out our help page on debugging import errors? https://help.pythonanywhere.com/pages/DebuggingImportError/

hello im checked it but it doesnt work :( the error continue

I really think that you need to look at the contents of the response you are getting from Binance; I see that Glenn asked you to do that on 2 May, and I did on 3 May, but you haven't said what the response contains. Please do that, as we can't help you without having the information that we've asked for.

Regarding the ModuleNotFound error, that is because serverTime is not something you should import; you need to remove the line that does that.

The procedure that I carry out is the following:

1 with postman I send the test request and it returns the following error: (POST METHOD)

<!doctype html> <html lang=en> <title>500 Internal Server Error</title> <h1>Internal Server Error</h1> <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

2 When executing the flask application that creates in pythonanywhere to call the application that I uploaded to pythonanywhere, it does not execute the process and when reviewing the error logs it generates the following error:

2023-05-09 15:44:53,746: Exception on /bot [POST] Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/LionsInv/mysite/main.py", line 20, in bot bot.Enter(message) File "/home/LionsInv/mysite/FuturosBot.py", line 52, in Enter pos = self.GetPosition(self.ticker) File "/home/LionsInv/mysite/FuturosBot.py", line 39, in GetPosition return c.GetPosition(ticker) File "/home/LionsInv/mysite/FuturosConsultas.py", line 40, in GetPosition pos = self.GetPositions() File "/home/LionsInv/mysite/FuturosConsultas.py", line 34, in GetPositions ac = self.GetGeneralAccount() File "/home/LionsInv/mysite/FuturosConsultas.py", line 27, in GetGeneralAccount params = "timestamp=" + str(self.GetServerDate()) File "/home/LionsInv/mysite/Binance.py", line 23, in GetServerDate return resp['serverTime'] KeyError: 'serverTime'

but when I run it on my computer it runs perfectly and makes the request to binance through the api Key, which generates a correct response,

What I want to say is that when I run the application in pythonanywhere it does not enter the module designed for the connection with binance, therefore binance does not generate an error log or at some point it does not allow me to continue and generates the error log that it shows me pythonanywhere I think of a difference between pythonanywhere server vs binance schedule or at some point some library or function does not allow the correct operation on the server

![in the software i bring servetime from binance api and execute that without problems1

![in the software i bring servetime from binance api and execute that without problems1

![in the software i bring servetime from binance api and execute that without problems1

Have you checked the contents of the response from Binance? One thing that comes to mind is that they might be blocking access from PythonAnywhere due to some kind of geographic restrictions.

I talked to binance support, they tell me that if the server hours are located in the USA, it will most likely not allow access, so I would like to know if the hours can be modified or is there any other solution?

OK, it sounds like your account will need to be migrated to our US systems. If you send us an email at support@pythonanywhere.com, then we can kick that process off.

ok im gonna to send that request

hello i was send the message 2 days ago but i dont have response

I see we've already replied you, so let's keep the conversation in emails.

can you tell me the solution for this?

For what?