Api error - Bad Gateway Error Code 502

Hello!

I have a python based program that interacts with chatGPT via openai API (query = search information About a company) - I have already processed many requests and with a proper timer it worked smoothly.

This afternoon (EU time) the program made some hits but now I have a message error (Bad Gateway - Error Code 502 see below) - My account is at Free Trial Level

=> Is this issue related to the ongoing level of requests (US users are waking up…)

Many thanks for any feedback on this problem.

Cordially,
Alexandre

APIError: Bad gateway. {"error":{"code":502,"message":"Bad gateway.","param":null,"type":"cf_bad_gateway"}} 502 {'error': {'code': 502, 'message': 'Bad gateway.', 'param': None, 'type': 'cf_bad_gateway'}} {'Date': 'Thu, 22 Jun 2023 14:58:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '84', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'same-origin', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Server': 'cloudflare', 'CF-RAY': '7db55245ce3a0076-CDG', 'alt-svc': 'h3=":443"; ma=86400'}
2 Likes

Welcome to the Forum! To help us help you, can you please provide some code snippets, in this case the code you have that makes the call to OpenAI and any setup code that it relies on. Thanks!

Hello Foxabillo!

Thanks for your interest on my issue.
You will find below the snippets you are asking for.
=> The behavior of the program seems to indicates that there is an throughput problem related to external (network?) resources.
The software is a simple loop that queries chatGPT for an “about a company”
The number of cycles before the error occurs are variable sometimes after a couple of queries other times after > 30 runs
Hence there is no correlation with a particular company

I thank you for your attention and look forward for your feedback.

Cordially,
Alexandre

keyAPI = '############################'
import openai
openai.api_key = keyAPI


def getAbout(CiaName):
    queryContent = "content"
    queryAbout = "Tell me about this Brazilian company: "
    brzCiaName = str(CiaName)

    queryMessage = [ {"role": "user", queryContent: queryAbout + brzCiaName} ]

    chat = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages = queryMessage)
    About = chat.choices[0].message.content
    return About

The loop:

while inputLine := cvm_fi.readline():
.....
    companyName = inputList[2]
     # we need know to get some info about the company by requesting chatGPT
      ciaAbout = getAbout(companyName)

Ok, and are you still getting the 502 error?

Hello!

I am going to try tomorrow morning when almost everybody in the US will be sleeping :kissing_heart:

2 Likes

Hello!

At 10h00 (GMT+2) after 20 successful cycles I got again an Error Code 502 (see below).
Thank you for your attention.
Cordially,
Alexandre

File c:\users\axdpa\appdata\local\programs\python\python39\lib\site-packages\openai\api_requestor.py:687, in APIRequestor._interpret_response_line(self, rbody, rcode, rheaders, stream)
    685 stream_error = stream and "error" in resp.data
    686 if stream_error or not 200 <= rcode < 300:
--> 687     raise self.handle_error_response(
    688         rbody, rcode, resp.data, rheaders, stream_error=stream_error
    689     )
    690 return resp

APIError: Bad gateway. {"error":{"code":502,"message":"Bad gateway.","param":null,"type":"cf_bad_gateway"}} 502 {'error': {'code': 502, 'message': 'Bad gateway.', 'param': None, 'type': 'cf_bad_gateway'}} {'Date': 'Mon, 26 Jun 2023 07:32:53 GMT', 'Content-Type': 'application/json', 'Content-Length': '84', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'same-origin', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Server': 'cloudflare', 'CF-RAY': '7dd3ba773eac0092-CDG', 'alt-svc': 'h3=":443"; ma=86400'}

Hi Alexo,

502 gateway errors are one of the more common network errors with modern distributed server systems, it means that one server got a bad response from another, i.e. an edge server to a central server. Usually a sign of a transient infrastructure outage.

Your code should gracefully handle the error, perhaps making a log fie entry and informing the user of the issue and it’s temporary nature and then implement a exponential back off and retry system where you wait twice as long as the last time each time you retry.

Build in some reasonable maximum wait period and allow the user to manually retry if that seems appropriate.

1 Like

Many thanks for your explanations !

My (company) loop is somehow slowed because it comprises two interactions with the user.

I included in the code a sequence to save data and close files after a crash - When the user restarts the program he can ask to Resume operations and then the program continues processing at the crash point.

Many thanks again for your dedication to this issue.

Wish you a great week :muscle:
Alexandre

2 Likes

I get a similar message saying:

Bad gateway. {“error”:{“code”:502,“message”:“Bad gateway.”,“param”:null,“type”:“cf_bad_gateway”}} 502 {‘error’: {‘code’: 502, ‘message’: ‘Bad gateway.’, ‘param’: None, ‘type’: ‘cf_bad_gateway’}} {‘Date’: ‘Wed, 26 Jul 2023 04:40:18 GMT’, ‘Content-Type’: ‘application/json’, ‘Content-Length’: ‘84’, ‘Connection’: ‘keep-alive’, ‘X-Frame-Options’: ‘SAMEORIGIN’, ‘Referrer-Policy’: ‘same-origin’, ‘Cache-Control’: ‘private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0’, ‘Expires’: ‘Thu, 01 Jan 1970 00:00:01 GMT’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘7ec9ef13ec1a6426-SJC’, ‘alt-svc’: ‘h3=“:443”; ma=86400’}

same here! can we get some help?
Error encountered: Bad gateway. {“error”:{“code”:502,“message”:“Bad gateway.”,“param”:null,“type”:“cf_bad_gateway”}} 502 {‘error’: {‘code’: 502, ‘message’: ‘Bad gateway.’, ‘param’: None, ‘type’: ‘cf_bad_gateway’}} {‘Date’: ‘Fri, 20 Oct 2023 00:58:39 GMT’, ‘Content-Type’: ‘application/json’, ‘Content-Length’: ‘84’, ‘Connection’:
‘keep-alive’, ‘X-Frame-Options’: ‘SAMEORIGIN’, ‘Referrer-Policy’:
‘same-origin’, ‘Cache-Control’: ‘private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0’, ‘Expires’: ‘Thu, 01 Jan 1970 00:00:01 GMT’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘818d5049be7b3165-DFW’, ‘alt-svc’: ‘h3=“:443”; ma=86400’}

1 Like

Hello everyone.
This message is happening very frequently as of this morning for requests to access gpt3.5 via the open AI API in python.

Bad gateway. {"error":{"code":502,"message":"Bad gateway.","param":null,"type":"cf_bad_gateway"}} 502 {'error': {'code': 502, 'message': 'Bad gateway.', 'param': None, 'type': 'cf_bad_gateway'}} {'Date': 'Fri, 20 Oct 2023 01:04:43 GMT', 'Content-Type': 'application/json', 'Content-Length': '84', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'same-origin', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Server': 'cloudflare', 'CF-RAY': '818d592e4fea3152-ICN', 'alt-svc': 'h3=":443"; ma=86400'}

Does anyone have any idea what is going on?

1 Like

I’m encountering the same issue as well; it seems there might be a slight problem with API calls now. refer to: https://status.openai.com/.

1 Like

Today morning, I also encountered the same error.

What is going on , how is this support , actually support. Use some of the money we pay and help resolve this!

{
“model”:“gpt-4”,
“messages”: [{“role”: “user”,
“content”: “use the askyourdatabase plugin and follow this prompt taking the role of a oracle plsql database developer for 23c. Create a oracle sql update table statement for table CRT_SKILLS. The three columns as follows are the Primary key integer called SKILL_ID, SKILL_NAME and CLOUD_SKILLS_DESCRIPTION. Use the field I will pass in later called SKILL_NAME and find as much info as will fill the maximum prompt size and generate update table statements to update the field CLOUD_SKILLS_DESCRIPTION with a detailed explaination of this cloud skillset, who typically is responsible for using this service, urls with more info on this skills description. IF space allows , please identify the source from which you obtained that detailed skills description. References to cloud best practices is apprecaited. I only want the response to be in the form of a single plsql block of code. I will later execute this plsql block by using a single execute immediate statement. Simply generate the plsql block to be executed with a begin, proper exception handling if the update should fail and end clause. I want you to use the PK column I will provide. I will give you the skill_id pk into table crt_skills. Most critical is that you escape any single quotes with a backslash, escape double quotes with a backslash. Any special characters that would make this data invalid must be escaped. Keep the resulting response to less than 4000 characters. Here is the format that I will be sending you later in this prompt. The skill_id and skill_name delimited by the tilde character with the record ending in tildeexclaimationpointtilde. Again the record will end when you see these three characters in sequence. Provide the details you find in a third column called cloud_skills_description. Use all the available response space possible. If your response will overfill the available response size possible keep the extra updates statements and return them in the next prompt. I do not want comments in the response. I dont want extra carriage returns , save space and sacrafice readability. Please build the most complete, compacted sql statements. For words that have an apostrophe, please use two apostrophes so that the insert statements do not fail because of confusion with escape characters or end of insert statements. Please scan the results returned in the update statement for any single apostropies if they are not at the beginning or end of the update statement and escape them so that this does not break the update statement. For ampersand & escape them so that the update statement is not paused for substitution often the case with sqlplus set define off. Here is the list of data to take action on. 10513~OCI Vault - Unknown”
}],
“temperature”: 0.5,
“max_tokens”: 4096}
{“error”:{“code”:502,“message”:“Bad gateway.”,“param”:null,“type”:“cf_bad_gateway”}}

1 Like

Same error with 502 this time.

How to fix this?

This is being looked into.

2 Likes

I also have same issue with 502 from this morning.

1 Like

I am also facing 502 issue this morning.
An exception occurred: Bad gateway. {“error”:{“code”:502,“message”:“Bad gateway.”,“param”:null,“type”:“cf_bad_gateway”}} 502 {‘error’: {‘code’: 502, ‘message’: ‘Bad gateway.’, ‘param’: None, ‘type’: ‘cf_bad_gateway’}} {‘Date’: ‘Fri, 20 Oct 2023 01:50:57 GMT’, ‘Content-Type’: ‘application/json’, ‘Content-Length’: ‘84’, ‘Connection’: ‘keep-alive’, ‘X-Frame-Options’: ‘SAMEORIGIN’, ‘Referrer-Policy’: ‘same-origin’, ‘Cache-Control’: ‘private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0’, ‘Expires’: ‘Thu, 01 Jan 1970 00:00:01 GMT’, ‘Server’: ‘cloudflare’, ‘CF-RAY’: ‘818d9ce6ef8f94cb-CCU’, ‘alt-svc’: ‘h3=“:443”; ma=86400’}

1 Like

There’s something wrong with the server. Even the openai playground runs into “internal server error”

1 Like

Uploading: image.png…
I am also facing 502 issue this morning.
Retrying langchain.llms.openai.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised APIError: Bad gateway. {"error":{"code":502,"message":"Bad gateway.","param":null,"type":"cf_bad_gateway"}} 502 {'error': {'code': 502, 'message': 'Bad gateway.', 'param': None, 'type': 'cf_bad_gateway'}} {'Date': 'Fri, 20 Oct 2023 01:53:13 GMT', 'Content-Type': 'application/json', 'Content-Length': '84', 'Connection': 'keep-alive', 'X-Frame-Options': 'SAMEORIGIN', 'Referrer-Policy': 'same-origin', 'Cache-Control': 'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires': 'Thu, 01 Jan 1970 00:00:01 GMT', 'Server': 'cloudflare', 'CF-RAY': '818da03b68a4042b-HKG', 'alt-svc': 'h3=":443"; ma=86400'}.

1 Like