Python3 执行报错 #68

Closed
opened 2026-02-16 11:19:39 -05:00 by yindo · 1 comment
Owner

Originally created by @greatbody on GitHub (Feb 18, 2025).

import requests
from random import randint

def main(arg1: str) -> dict:
    url = "https://api.siliconflow.cn/v1/images/generations"

    payload = {
        "model": "deepseek-ai/Janus-Pro-7B",
        "prompt": arg1,
        "seed": randint(1, 9999999999)
    }
    headers = {
        "Authorization": "Bearer sk-b",
        "Content-Type": "application/json"
    }

    try:
        response = requests.request("POST", url, json=payload, headers=headers, timeout=600)

        if response.status_code == 200:
            response_json = response.json()
            print(response_json)
            if response_json.get("images") and len(response_json["images"]) > 0:
                return {
                    "result": response_json["images"][0]["url"]
                }
            return {
                "result": "ERROR"
            }
        else:
            return {
                "result": f"HTTP Error: {response.status_code}"
            }
    except Exception as e:
        return {
            "result": f"Error: {str(e)}"
        }

本地 VSCode 运行报 http status code 451
但是 Dify 里面报的是超时。

Originally created by @greatbody on GitHub (Feb 18, 2025). ```python import requests from random import randint def main(arg1: str) -> dict: url = "https://api.siliconflow.cn/v1/images/generations" payload = { "model": "deepseek-ai/Janus-Pro-7B", "prompt": arg1, "seed": randint(1, 9999999999) } headers = { "Authorization": "Bearer sk-b", "Content-Type": "application/json" } try: response = requests.request("POST", url, json=payload, headers=headers, timeout=600) if response.status_code == 200: response_json = response.json() print(response_json) if response_json.get("images") and len(response_json["images"]) > 0: return { "result": response_json["images"][0]["url"] } return { "result": "ERROR" } else: return { "result": f"HTTP Error: {response.status_code}" } except Exception as e: return { "result": f"Error: {str(e)}" } ``` 本地 VSCode 运行报 http status code 451 但是 Dify 里面报的是超时。
yindo added the bug label 2026-02-16 11:19:39 -05:00
yindo closed this issue 2026-02-16 11:19:40 -05:00
Author
Owner

@greatbody commented on GitHub (Mar 28, 2025):

@crazywoola Do we consider it a bug or just my environment issue?

@greatbody commented on GitHub (Mar 28, 2025): @crazywoola Do we consider it a bug or just my environment issue?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs-archived#68