xhcoding / emacs-aichat

AI Chat in Emacs, including OpenAI and Bing Chat
62 stars 8 forks source link

Error: (error (error (error (error Can not get correct cookie for login!)))) #28

Closed liar666 closed 10 months ago

liar666 commented 10 months ago

Still having a lot of trouble with my DoomEmacs config, thus I'm rewriting it from scratch, piece by piece. DoomEmacs gets emacs-aichat directly from github repo with straight.el.

I've started with very few things, included the one that fails most often: emacs-aichat.

Here is the config:

(use-package! aichat
  :bind
  (:map global-map
    ("C-S-a" . #'aichat-bingai-assistant)
    ("C-S-c" . #'aichat-bingai-chat)
  )
)
(after! aichat
    ;; (require 'aichat)
    ;; (require 'aichat-bingai)
    ;; (setq aichat-browser-name 'firefox)
    (setq aichat-bingai-cookies-file "~/.doom.d/packages/cookie.json")
    (require 'aichat-bingai)
)

When I call aichat-bingai-assistant with "C-S-a" on some selected text, I get an error.

Thus I tried what you advised recently:

(require 'aichat)
(require 'aichat-bingai)
(aichat-get-cookies-from-file "~/.doom.d/packages/cookie.json")

There seems to be a cookie loaded. Then calling aichat-bingai-assistant with "C-S-a" on some selected text, again.

Here is the output in the *Message* buffer (I indented & anonymized the cookie content. Otherwise it is untouched):

aichat
aichat-bingai

(("ANON"
  "A=<code>&E=<code>&W=1"
  "2024-01-28T23:33:42+0100"
  ".bing.com"
  "/"
  t)
 ("BCP"
  "AD=<code>&AL=<code>&SM=0"
  "2024-07-28T00:33:45+0200"
  ".bing.com"
  "/"
  t)
 ("CSRFCookie"
  "a6fb11c7-d4a6-49c3-a363-4069b68ad28b"
  nil
  ".bing.com"
  "/"
  t)
 ("KievRPSSecAuth"
  "<code2>"
  "2024-08-22T00:33:42+0200"
  ".bing.com"
  "/"
  t)
 ("MUID"
  "<id>"
  "2024-08-22T00:33:28+0200"
  ".bing.com"
  "/"
  t)
 ("MUIDB"
  "<id>"
  "2024-08-22T00:35:16+0200"
  "www.bing.com"
  "/"
  t)
 ("NAP"
  "V=1.9&E=<code>&C=NQmAJcI2U5C29-jXIkBEm0X0LInWBRClmvcaQUfX7PYZVXBNZ1AFrA&W=1"
  "2024-02-14T07:33:41+0100"
  ".bing.com"
  "/"
  t)
 ("PPLState"
  "1"
  "2024-08-22T00:33:42+0200"
  ".bing.com"
  "/"
  t)
 ("SRCHD"
  "AF=NOFORM"
  "2024-08-22T00:33:28+0200"
  ".bing.com"
  "/"
  t)
 ("SRCHHPGUSR"
  "SRCHLANG=<code>&BRW=<code>&BRH=<code>&CW=<code>&CH=<code>&SCW=<code>&SCH=<code>&DPR=1.0&UTC=<code>&DM=<code>&HV=<code>&WTS=<code>&PRVCW=<code>&PRVCH=<code>&EXLTT=3"
  "2024-08-22T00:35:19+0200"
  ".bing.com"
  "/"
  t)
 ("SRCHUID"
  "V=<code>&GUID=<code>&dmnchg=1"
  "2024-08-22T00:33:28+0200"
  ".bing.com"
  "/"
  t)
 ("SRCHUSR"
  "DOB=<code>&T=<code>&POEX=W"
  "2024-08-22T00:33:31+0200"
  ".bing.com"
  "/"
  t)
 ("SUID"
  "A"
  "2023-07-29T12:33:42+0200"
  ".bing.com"
  "/"
  t)
 ("USRLOC"
  "HS=1"
  "2024-08-22T00:35:04+0200"
  ".bing.com"
  "/"
  t)
 ("WLID"
  "eQHBjNxX+3Kcet1M33QshAVrqq8cLsi4IO2+WeJ8HLf4vsmfpyOlXrz6XQywKtoUhTDon499gwtJWQCzeFUrMAYw+DsUNsqh+0d01EHjB54="
  "2023-08-12T00:33:42+0200"
  ".bing.com"
  "/"
  t)
 ("WLS"
  "C=<code>&N=guillaume"
  nil
  ".bing.com"
  "/"
  t)
 ("_EDGE_S"
  "F=<code>&SID=2BE0F3EC890E67F52310E0B088B7660A"
  nil
  ".bing.com"
  "/"
  t)
 ("_EDGE_V"
  "1"
  "2024-08-22T00:33:28+0200"
  ".bing.com"
  "/"
  t)
 ("_HPVN"
  "CS=<code2>"
  "2024-08-22T00:33:46+0200"
  ".bing.com"
  "/"
  t)
 ("_RwBf"
  "ilt=<code>&ihpd=<code>&ispd=<code>&rc=<code>&rb=<code>&gb=<code>&rg=<code>&pc=<code>&mtu=<code>&rbb=<code>&g=<code>&cid=<code>&clo=<code>&v=<code>&l=2023-07-28T07:00:00.0000000Z&lft=0001-01-01T00:00:00.0000000&aof=<code>&o=<code>&p=<code>&c=<code>&t=<code>&s=2023-03-01T21:25:05.4851788+00:00&ts=2023-07-28T22:35:11.5437932+00:00&rwred=<code>&wls=<code>&lka=<code>&lkt=<code>&TH=<code>&dci=<code>&mta=<code>&e=<code2>&A=<id>"
  "2024-08-22T00:35:16+0200"
  ".bing.com"
  "/"
  t)
 ("_SS"
  "SID=<code>&R=<code>&RB=<code>&GB=<code>&RG=<code>&RP=27"
  nil
  ".bing.com"
  "/"
  t)
 ("_U"
  "<code2>"
  "2023-08-12T00:33:42+0200"
  ".bing.com"
  "/"
  t)
 ("_UR"
  "QS=<code>&TQS=0"
  "2024-08-22T00:33:43+0200"
  ".bing.com"
  "/"
  t)
 ("dsc"
  "order=ShopOrderNewsOverShop"
  nil
  ".bing.com"
  "/"
  t)
 ("ipv6"
  "hit=<code>&t=6"
  nil
  ".bing.com"
  "/"
  t))
Mark set
Saving file /home/guillaume.muller/.emacs.d/.local/cache/url/cookies...
Wrote /home/guillaume.muller/.emacs.d/.local/cache/url/cookies
Error: (error (error (error (error Can not get correct cookie for login!))))

Apparently, emacs-aichat does not manage to extract the cookie anymore. The exact same cookie.json was working a few days ago (but I doom upgraded since then).

Since my config is now minimal, and even the commands you provided earlier do not work. I don't think my config is the problem. Is there any change in Bing API?

xhcoding commented 10 months ago
("_U"
  "<code2>"
  "2023-08-12T00:33:42+0200"
  ".bing.com"
  "/"
  t)

It looks like the _U field in the cookie has expired. Try exporting a new cookie

liar666 commented 10 months ago

Woaw... Finally.... After reinstalling my whole DoomEmacs config from scratch for the nth time, I got asked again to unlock/configure my KWallet. Previous times, I just hit cancel and was never asked again, but cookie stuff was working only when it wanted. This time, I went for the complete configration of a default kwallet. It took some time and in the end, I saw this error in the *Message* buffer:

Auto-saving...done
#s(promise-class 0 2 (:timeouted) nil nil)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 1061, in edge
    return Edge(cookie_file, domain_name, key_file).load()
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 733, in __init__
    super().__init__(browser='Edge', cookie_file=cookie_file, domain_name=domain_name, key_file=key_file, **args)
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 381, in __init__
    self.__add_key_and_cookie_file(**kwargs)
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 394, in __add_key_and_cookie_file
    password = _LinuxPasswordManager(USE_DBUS_LINUX).get_password(os_crypt_name)
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 226, in get_password
    return self.__methods_map.get('kwallet')(os_crypt_name)
  File "/home/user/.local/lib/python3.10/site-packages/browser_cookie3/__init__.py", line 273, in __get_kdewallet_password_dbus
    handle = kwalletd5.open(kwalletd5.networkWallet(), dbus.Int64(0), self._APP_ID)
  File "/usr/lib/python3/dist-packages/dbus/proxies.py", line 141, in __call__
    return self._connection.call_blocking(self._named_service,
  File "/usr/lib/python3/dist-packages/dbus/connection.py", line 652, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
End of buffer [6 times]

Seems we are narrowing down on the error... Remains to find a (definitive) solution...

liar666 commented 10 months ago

Also, as you can see, it seems to look for a cookie in Edge, whereas my config.org has:

(setq aichat-browser-name 'firefox) ; and/or
(setq aichat-bingai-cookies-file "~/.doom.d/packages/cookie.json")
liar666 commented 10 months ago

Oh! Sorry I did'nt see your answer...