DarkCat09 / python-aternos

[UNMAINTAINED] Unofficial Aternos API written in Python
https://pypi.org/project/python-aternos/
Apache License 2.0
92 stars 13 forks source link

Token and SEC are empty when logging in with session cookie #80

Closed 1Marcuth closed 1 year ago

1Marcuth commented 1 year ago

Code:

from python_aternos import Client

aternos = Client()

aternos.login_with_session('---')

account = aternos.account
# Get servers list
servs = account.list_servers()
print(account.servers[0].port)
print(len(servs))

myserv = servs[0]
print(myserv.is_java)

myserv.start()

Error

Traceback (most recent call last):
  File "d:\programming\projects\actives\python\mc-server-bot\main.py", line 27, in <module>
    myserv.start()
  File "D:\programming\projects\actives\python\mc-server-bot\.venv\Lib\site-packages\python_aternos\atserver.py", line 149, in start
    startreq = self.atserver_request(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\programming\projects\actives\python\mc-server-bot\.venv\Lib\site-packages\python_aternos\atconnect.py", line 282, in request_cloudflare
    req.raise_for_status()
  File "D:\programming\projects\actives\python\mc-server-bot\.venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://aternos.org/ajax/server/start?headstart=0&access-credits=0&TOKEN=&SEC=
DarkCat09 commented 1 year ago

@1Marcuth,

Did you cut out the values of TOKEN and SEC parameters in the URL?
This data is not secret.
If python-aternos doesn't generate valid token and SEC, it is a really important issue.

1Marcuth commented 1 year ago

Did you cut out the values of TOKEN and SEC parameters in the URL? This data is not secret. If python-aternos doesn't generate valid token and SEC, it is a really important issue.

I put the right value in the original code

Poleric commented 1 year ago

Same issue here.

A bit hacky but this worked for me.

# run once
myserv.atconn.parse_token()
myserv.atconn.generate_sec()

myserv.start()
1Marcuth commented 1 year ago
myserv.atconn.parse_token()
myserv.atconn.generate_sec()

Then the server information was missing, I used myserv.fetch() and it worked! Thank you very much! :D

DarkCat09 commented 1 year ago

@Poleric, @1Marcuth,

Thanks a lot. Fixed.