OpenAI Error: 403 Country, region, or territory not supported [Python]

题意

从OpenAI的API服务中获取数据时,由于你所在的国家、地区或领土不被支持,因此请求被拒绝了

问题背景:

I have tried to run openai API in python with this code:

尝试在Python中使用OpenAI的API

client = OpenAI(api_key='sk-...')


def response(question):
    response = client.chat.completions.create(
      model="gpt-4-turbo-preview",
      messages=[
        {
           "role": "user",
           "content": question 
        }
      ]
)


if __name__ == '__main__':
  response(question)

But I get this error:        但是我得到下面的错误

openai.PermissionDeniedError: Error code: 403 - {'error&
Sure, here is a Python code that solves the problem using the Floyd-Warshall algorithm: ```python INF = float('inf') def find_min_cost(n, c, w): for k in range(n): for i in range(n): for j in range(n): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) w[i][j] = min(w[i][j], c[i][j] + min(w[i][k], w[k][j])) return sum(sum(row) for row in w) n = int(input()) c = [] w = [] for i in range(n): c_row = list(map(int, input().split())) c.append(c_row) w_row = [INF if x == 0 else x for x in c_row] w.append(w_row) print(find_min_cost(n, c, w)) ``` This code takes the input of `n`, the size of the matrix, `c`, the cost of connecting two industrial facilities, and `w`, the cost of crude oil exploration. It then initializes the `INF` constant to represent infinity and sets the diagonal of `w` to infinity since exploration is not required for facilities that already have oil. The algorithm then uses three nested loops to calculate the minimum cost of connecting all the facilities. It first calculates the shortest path between two facilities using the `c` matrix with the Floyd-Warshall algorithm. It then calculates the cost of supplying oil to each facility by adding the cost of connecting the facility to the nearest facility with oil and the cost of exploration if necessary. Finally, the algorithm returns the total minimum cost of supplying oil to all facilities by summing up the values in the `w` matrix. Please note that this code assumes that the input is valid and follows the problem statement. It also assumes that the input is formatted correctly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值