Hello, I got this error when I try to lunch my test script in Phyhon on my Mac os:
This is the error in my terminal:
File " in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host api. openai. com:443 ssl:True [SSLCertVerificationError: (1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)’)]
My script try to generate a random username:
import aiohttp
import json
import asyncio
async def generate_username_with_chatgpt(prompt, api_key):
url = "https://api . openai . com/v1/completions" # Verifica che questo sia l'URL corretto
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
payload = {
"model": "gpt-3.5-turbo", # Assicurati che il modello sia disponibile
"prompt": prompt,
"max_tokens": 60,
"n": 1,
"stop": None,
"temperature": 0.5,
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, data=json.dumps(payload)) as response:
if response.status == 200:
resp_json = await response.json()
username = resp_json['choices'][0]['text'].strip()
return username
else:
print(f"Errore nella richiesta API: {response.status}")
return None
async def main():
api_key = '*********' # Sostituisci con il tuo vero API key
prompt = ('Genera un nome utente che include una combinazione casuale di lettere e numeri, '
'con una parola specifica seguita da un numero casuale, e che sia lungo complessivamente '
'tra 8 e 12 caratteri.')
username = await generate_username_with_chatgpt(prompt, api_key)
print(f"Nome utente generato: {username}")
if __name__ == "__main__":
asyncio.run(main())
I don’t know why