Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session token no longer working. #1

Closed
WrappedUsername opened this issue Dec 11, 2022 · 8 comments
Closed

Session token no longer working. #1

WrappedUsername opened this issue Dec 11, 2022 · 8 comments

Comments

@WrappedUsername
Copy link

WrappedUsername commented Dec 11, 2022

I export SESSION_TOKEN="my-token-here", but it stopped accepting the token, looks like a fetch error.

Error: ChatGPT failed to refresh auth token. 
FetchError: invalid json response body at https://chat.openai.com/api/auth/session 
reason: Unexpected token < in JSON at position 0
@productive-programmer
Copy link
Owner

productive-programmer commented Dec 11, 2022

Hmm haven't run into this issue personally

Did you log out of https://chat.openai.com/ because that may have invalidated the session token, also I would double check if SESSION_TOKEN variable is still set I'm not certain if you changed terminals for instance or how much time has passed from the time it worked to not working. You could add the session token as a .env file in the future so it loads everytime the app loads.

@WrappedUsername
Copy link
Author

I asked ChatGPT why I am getting the error,

Why am I getting this error: 

Error: ChatGPT failed to refresh auth token.
FetchError: invalid json response body at https://chat.openai.com/api/auth/session reason:
Unexpected token < in JSON at position 0

ChatGPT suggested:

Check the expiration date of the authentication token and make sure it is still valid. If the token has expired, you will need to generate a new one and use it instead.

I asked ChatGPT to check if the token was expired:

The current date and time is Sunday, December 11, 2023, 3:56 Central time zone. Now can you give me a result?

import datetime
import pytz

# Define the expiration date and time in UTC
expiration_date = datetime.datetime(2023, 1, 10, 21, 49, 9, 763000, tzinfo=pytz.utc)

# Get the current date and time in the specified time zone
timezone = pytz.timezone('America/Chicago')
now = datetime.datetime.now(timezone)

# Calculate the duration of the session token in seconds
duration = (expiration_date - now).total_seconds()

# Print the duration of the session token
print(duration)

This code calculates the difference between the expiration date and the current date and time in the specified time zone (Central time in this case), and then prints the result. The result will be the duration of the session token in seconds.

In this specific case, the duration of the session token would be approximately 104444000 seconds, which is approximately 1206.5 hours or 50.3 days.

I hope this helps! Let me know if you have any other questions.

ChatGPT suggested:

If the connectivity to the authentication server is not the issue, you can try clearing the authentication cache and then re-authenticating with the API. This can sometimes fix issues with invalid or expired authentication tokens.

@WrappedUsername
Copy link
Author

It's strange because my token allows me to use the ChatGPT on their website but when I try to used the ai-chatbot in terminal, nope!

@productive-programmer
Copy link
Owner

I think it's an issue that just started with a recent update actually. transitive-bullshit/agentic#96

@WrappedUsername
Copy link
Author

Oh cool! An update no worries! Yes I was wanting to do an .env file also, but I am getting a typescript error about process needs Node.js, would I just set up a TypeScript file? Or do a full Next app? To get node.js to use process.env? Thanks for the help I still have so much to learn!

@productive-programmer
Copy link
Owner

No Worries, hopefully this will get resolved soon!

@productive-programmer
Copy link
Owner

productive-programmer commented Dec 20, 2022

IMPORTANT UPDATE: The SESSION_TOKEN solution no longer works (since the time I recorded my video). But, you can modify this code to use your username and password as a login as of the time I'm writing this message, For more details on how to do that along with the latest authentication strategies can be located here: https://github.com/transitive-bullshit/chatgpt-api

Anyone who wishes to update this repository by sending over a pull request to keep it up to date is welcomed and appreciated

@WrappedUsername
Copy link
Author

WrappedUsername commented Dec 20, 2022

Awesome, thank you:
  • I can try to work on the update, but please forgive me if I make any mistakes, I only have a little over a year of self-taught training!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants