chatgpt-webapi icon indicating copy to clipboard operation
chatgpt-webapi copied to clipboard

Access denied to ChatGPT

Open maxmeyer opened this issue 2 years ago • 2 comments

Is there anything I can do about it? I configured all cookies as described in the README. Looks like Cloudflare is blocking me.

2023/04/23 11:48:11 http response info: 
HTTP/2.0 403 Forbidden
Alt-Svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Cf-Mitigated: challenge
Cf-Ray: 7bc5307aed96cb11-DUS
Content-Type: text/html; charset=UTF-8
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
Date: Sun, 23 Apr 2023 09:48:11 GMT
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Permissions-Policy: accelerometer=(),autoplay=(),camera=(),clipboard-read=(),clipboard-write=(),fullscreen=(),geolocation=(),gyroscope=(),hid=(),interest-cohort=(),magnetometer=(),microphone=(),payment=(),publickey-credentials-get=(),screen-wake-lock=(),serial=(),sync-xhr=(),usb=()
Referrer-Policy: same-origin
Server: cloudflare
Set-Cookie: __cf_bm=XXXXXXX; path=/; expires=Sun, 23-Apr-23 10:18:11 GMT; domain=.chat.openai.com; HttpOnly; Secure; SameSite=None
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Robots-Tag: nofollow


2023/04/23 11:48:11 http response info: <html>
  <head>
    <style global>body{font-family:Arial,Helvetica,sans-serif}.container{align-items:center;display:flex;flex-direction:column;gap:2rem;height:100%;justify-content:center;width:100%}@keyframes enlarge-appear{0%{opacity:0;transform:scale(75%) rotate(-90deg)}to{opacity:1;transform:scale(100%) rotate(0deg)}}.logo{color:#8e8ea0}.scale-appear{animation:enlarge-appear .4s ease-out}@media (min-width:768px){.scale-appear{height:48px;width:48px}}.data:empty{display:none}.data{border-radius:5px;color:#8e8ea0;text-align:center}@media (prefers-color-scheme:dark){body{background-color:#343541}.logo{color:#acacbe}}</style>
  
</head>
....
      <div class="data"><form id="challenge-form" class="challenge-form" action="/api/auth/session?__cf_chl_f_tk=2qQUwEBfpgXHMEERbqIHxaQ45cLMnMjZX9tpDHYDf.M-1682243291-0-gaNycGzNFuU" method="POST" enctype="application/x-www-form-urlencoded">
    <div id="cf-please-wait">
        <div id="spinner">
            <div id="cf-bubbles">
                <div class="bubbles"></div>
                <div class="bubbles"></div>
                <div class="bubbles"></div>
            </div>
        </div>
        <p id="cf-spinner-please-wait">Please stand by, while we are checking your browser...</p>
        <p id="cf-spinner-redirecting" style="display:none">Redirecting...</p>
    </div>
....
2023/04/23 11:48:11 get chat text failed: send message failed: get accessToken failed: invalid session data: 

maxmeyer avatar Apr 23 '23 10:04 maxmeyer

same issue for me

get chat text failed: send message failed: get accessToken failed: fetch new accessToken failed: parse response body failed

Looks like there is now a Cloudflare protection to limit or stop chatgpt bot:

When calling /api/auth/session endpoint there is a cloudflare challenge page designed to determine whether the request was sent by a human or a robot.

wawagit avatar Apr 25 '23 13:04 wawagit

works for me when setting this user agent:

cli := chatgpt.NewClient( chatgpt.WithTimeout(620*time.Second), chatgpt.WithCookies(cookies), chatgpt.WithModel("gpt-4-32k"), // UserAgent chatgpt.WithUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"), )

wawagit avatar Apr 25 '23 14:04 wawagit