提交 organization/select,返回 continue_url 或回调地址。
(
self,
*,
org_id: str,
project_id: str = "",
referer: str,
did: str = "",
)
| 2671 | return None |
| 2672 | |
| 2673 | def _select_organization( |
| 2674 | self, |
| 2675 | *, |
| 2676 | org_id: str, |
| 2677 | project_id: str = "", |
| 2678 | referer: str, |
| 2679 | did: str = "", |
| 2680 | ) -> Optional[str]: |
| 2681 | """提交 organization/select,返回 continue_url 或回调地址。""" |
| 2682 | try: |
| 2683 | payload = {"org_id": org_id} |
| 2684 | if project_id: |
| 2685 | payload["project_id"] = project_id |
| 2686 | headers = self._build_json_headers( |
| 2687 | referer=referer, |
| 2688 | include_device_id=True, |
| 2689 | did=did, |
| 2690 | ) |
| 2691 | response = self.session.post( |
| 2692 | OPENAI_API_ENDPOINTS["select_organization"], |
| 2693 | headers=headers, |
| 2694 | data=json.dumps(payload), |
| 2695 | allow_redirects=False, |
| 2696 | ) |
| 2697 | self._log(f"organization/select 状态: {response.status_code}") |
| 2698 | |
| 2699 | location = str(response.headers.get("Location") or "").strip() |
| 2700 | if response.status_code in [301, 302, 303, 307, 308] and location: |
| 2701 | import urllib.parse |
| 2702 | continue_url = urllib.parse.urljoin(OPENAI_API_ENDPOINTS["select_organization"], location) |
| 2703 | self._log(f"Organization Continue URL (Location): {continue_url[:100]}...") |
| 2704 | return continue_url |
| 2705 | |
| 2706 | if response.status_code != 200: |
| 2707 | self._log(f"organization/select 失败: {response.status_code}", "warning") |
| 2708 | return None |
| 2709 | |
| 2710 | try: |
| 2711 | payload = response.json() or {} |
| 2712 | except Exception as json_err: |
| 2713 | self._log(f"解析 organization/select 响应失败: {json_err}", "warning") |
| 2714 | return None |
| 2715 | |
| 2716 | continue_url = str(payload.get("continue_url") or "").strip() |
| 2717 | if continue_url: |
| 2718 | continue_url = continue_url.replace("\\/", "/") |
| 2719 | self._log(f"Organization Continue URL: {continue_url[:100]}...") |
| 2720 | return continue_url |
| 2721 | return None |
| 2722 | except Exception as e: |
| 2723 | self._log(f"选择 Organization 失败: {e}", "error") |
| 2724 | return None |
| 2725 | |
| 2726 | def _select_workspace(self, workspace_id: str) -> Optional[str]: |
| 2727 | """选择 Workspace,并在需要时提交 organization/select。""" |
no test coverage detected