Fix redirect failed

This commit is contained in:
hibobmaster 2023-03-22 23:40:32 +08:00
parent f5f8ef8429
commit 6f1420f484
No known key found for this signature in database
GPG Key ID: FC3F06DF7EA00106
2 changed files with 9 additions and 3 deletions

View File

@ -46,10 +46,15 @@ class ImageGen:
url = f"{BING_URL}/images/create?q={url_encoded_prompt}&rt=4&FORM=GENCRE"
response = self.session.post(url, allow_redirects=False)
if response.status_code != 302:
logger.error(f"ERROR: {response.text}")
return []
#if rt4 fails, try rt3
url= f"{BING_URL}/images/create?q={url_encoded_prompt}&rt=3&FORM=GENCRE"
response3 = self.session.post(url, allow_redirects=False)
if response3.status_code != 302:
logger.error(f"ERROR: {response.text}")
return []
response=response3
# Get redirect URL
redirect_url = response.headers["Location"]
redirect_url = response.headers["Location"].replace("&nfy=1", "")
request_id = redirect_url.split("id=")[-1]
self.session.get(f"{BING_URL}{redirect_url}")
# https://www.bing.com/images/create/async/results/{ID}?q={PROMPT}

View File

@ -6,6 +6,7 @@ RUN pip3 install --user -r /requirements.txt && rm /requirements.txt
FROM python:3.11-alpine as runner
LABEL "org.opencontainers.image.source"="https://github.com/hibobmaster/matrix_chatgpt_bot"
RUN apk update && apk add olm-dev libmagic
COPY --from=pybuilder /root/.local /usr/local
COPY --from=pybuilder /usr/share/zoneinfo /usr/share/zoneinfo