|
44 | 44 |
|
45 | 45 | EXIT_CODE_WHEN_ADDRESS_ALREADY_IN_USE = 13 |
46 | 46 |
|
| 47 | +CA_CONTEXT = None |
| 48 | +try: |
| 49 | + import ssl |
| 50 | + import certifi as _certifi |
| 51 | + |
| 52 | + CA_CONTEXT = ssl.create_default_context(cafile=_certifi.where()) |
| 53 | +except Exception: |
| 54 | + pass |
| 55 | + |
47 | 56 |
|
48 | 57 | @dataclass |
49 | 58 | class TokenData: |
@@ -255,7 +264,8 @@ def _obtain_api_key( |
255 | 264 | data=exchange_data, |
256 | 265 | method="POST", |
257 | 266 | headers={"Content-Type": "application/x-www-form-urlencoded"}, |
258 | | - ) |
| 267 | + ), |
| 268 | + context=CA_CONTEXT, |
259 | 269 | ) as resp: |
260 | 270 | exchange_payload = json.loads(resp.read().decode()) |
261 | 271 | exchanged_access_token = exchange_payload["access_token"] |
@@ -326,7 +336,8 @@ def _exchange_code(self, code: str) -> tuple[AuthBundle, str]: |
326 | 336 | data=data, |
327 | 337 | method="POST", |
328 | 338 | headers={"Content-Type": "application/x-www-form-urlencoded"}, |
329 | | - ) |
| 339 | + ), |
| 340 | + context=CA_CONTEXT, |
330 | 341 | ) as resp: |
331 | 342 | payload = json.loads(resp.read().decode()) |
332 | 343 |
|
@@ -506,7 +517,7 @@ def maybe_redeem_credits( |
506 | 517 | headers={"Content-Type": "application/json"}, |
507 | 518 | ) |
508 | 519 |
|
509 | | - with urllib.request.urlopen(req) as resp: |
| 520 | + with urllib.request.urlopen(req, context=CA_CONTEXT) as resp: |
510 | 521 | refresh_data = json.loads(resp.read().decode()) |
511 | 522 | new_id_token = refresh_data.get("id_token") |
512 | 523 | new_id_claims = parse_id_token_claims(new_id_token or "") |
@@ -596,7 +607,7 @@ def maybe_redeem_credits( |
596 | 607 | headers={"Content-Type": "application/json"}, |
597 | 608 | ) |
598 | 609 |
|
599 | | - with urllib.request.urlopen(req) as resp: |
| 610 | + with urllib.request.urlopen(req, context=CA_CONTEXT) as resp: |
600 | 611 | redeem_data = json.loads(resp.read().decode()) |
601 | 612 |
|
602 | 613 | granted = redeem_data.get("granted_chatgpt_subscriber_api_credits", 0) |
|
0 commit comments