You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pushover脚本无报错但收不到推送,智能门铃项目求助

Troubleshooting Your Pushover API Notification Issue

Hey there! Let's dig into why your Python 3 script isn't sending Pushover notifications even though it runs without throwing errors. I’ve looked over your code and have a few actionable fixes to try out:

1. Fix the Extra Spaces in Your API Keys

First off, I notice your app_key and user_key have extra spaces around them (like " app key "). Pushover’s API keys are strict—any leading/trailing whitespace will cause authentication to fail. Remove those spaces so your keys look like this:

app_key = "your_real_app_key"
user_key = "your_real_user_key"

Double-check that you’re copying the exact keys from your Pushover dashboard (no typos or missing characters!).

2. Log the API Response to See Hidden Errors

Right now, your code calls conn.getresponse() but doesn’t actually read or print the response. Pushover might be sending back an error message (like invalid credentials or missing parameters) that you’re not seeing. Update your function to log the response details:

def pushOver(title,message,url):
    app_key = "your_real_app_key"
    user_key = "your_real_user_key"
    conn = http.client.HTTPSConnection("api.pushover.net:443")
    conn.request("POST", "/1/message.json",
        urllib.parse.urlencode({
            "token": app_key,
            "user": user_key,
            "title": title,
            "message": message,
            "url": url,
        }),
        { "content-type": "application/x-www-form-urlencoded" }
    )
    # Read and print the response to debug
    response = conn.getresponse()
    print(f"Status Code: {response.status}")
    print(f"Response Message: {response.reason}")
    print(f"Full Response: {response.read().decode('utf-8')}")

Run the script again—this will show you exactly what Pushover is sending back, which is critical for debugging.

3. Check the Empty url Parameter

You’re passing an empty string for url in your test call. While Pushover allows optional parameters, sometimes empty values can cause unexpected behavior. Try either:

  • Omitting the url key entirely from the payload if you don’t need it, or
  • Passing a valid test URL like "https://example.com" to see if that resolves the issue.

The http.client and urllib modules work, but they’re a bit clunky for API calls. The requests library makes this way easier and more readable. Here’s how to rewrite your function with it:

  1. First install the library:
    pip install requests
    
  2. Update your code:
    import requests
    
    def pushOver(title, message, url):
        app_key = "your_real_app_key"
        user_key = "your_real_user_key"
        payload = {
            "token": app_key,
            "user": user_key,
            "title": title,
            "message": message
        }
        # Only add url if it's not empty
        if url.strip():
            payload["url"] = url
        
        response = requests.post("https://api.pushover.net/1/message.json", data=payload)
        print("API Response:", response.json())
    

This will automatically handle encoding and give you a JSON response that’s easy to parse for errors.

5. Verify Pushover Account/Device Settings

Before diving deeper into code, double-check these basics:

  • Make sure your user key matches the one in your Pushover Account Settings
  • Confirm your app key is linked to the correct application you created in Pushover
  • Ensure your target device is registered in your Pushover account and isn’t in Do Not Disturb mode

Start with the first fix (removing spaces from keys)—that’s the most common culprit here. Then use the response logging to see if any other issues pop up.

内容的提问来源于stack exchange,提问作者Ash Stirland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:24:19