使用Walmart测试通知API验证Webhook端点时遭遇500内部服务器错误的排查求助
Walmart测试通知API验证Webhook端点时遭遇500内部服务器错误的排查求助
我在使用Walmart测试通知API验证我的Webhook端点URL时,它返回了**"(500 internal server error)"**。但我手动通过Putty服务器的cmd发送curl post请求到该端点URL,附带假的JSON数据时,请求能被端点正常处理。而且我的服务器背后也没有运行防火墙,实在搞不懂为什么会出现这个错误?
我的测试请求代码:
def test_notification(access_token): url = "https://marketplace.walmartapis.com/v3/webhooks/test" evt_url = "https://example.com/price-track/wm_test/wb_test.php" event_type = "OFFER_UNPUBLISHED" resourceName = "ITEM" headers = { "Accept": "application/json;", "Content-Type": "application/json;", "WM_SEC.ACCESS_TOKEN": access_token, "WM_SVC.NAME": "Walmart Marketplace", "WM_QOS.CORRELATION_ID": "vemutriruvelganuku6arksogaueora6" } notification_payload = { "eventType": event_type, "eventVersion": "V1", "resourceName": resourceName, "eventUrl": evt_url, "headers": { "content-type": "application/json;" } } logging.info("Sending Walmart webhook test notification") logging.debug(f"URL: {url}") logging.debug(f"Headers: {json.dumps(headers, indent=4)}") logging.debug(f"Payload: {json.dumps(notification_payload, indent=4)}") try: # response = requests.post(url, headers=headers, data=json.dumps(notification_payload)) response = requests.post(url, headers=headers, json=notification_payload) logging.info(f"Response Status Code: {response.status_code}") logging.debug(f"Response Headers: {response.headers}") logging.debug(f"Response Text: {response.text}") if response.status_code != 200: response_data = response.json() logging.error(f"Error Response JSON: {json.dumps(response_data, indent=4)}") return response.text if response.status_code == 200 else f"Error code: {response.status_code} - Error Message: {response.text}" except requests.exceptions.RequestException as e: logging.error(f"Request failed: {str(e)}", exc_info=True) return f"Request failed: {str(e)}" client_id = 'dbbcd0e08...............fg3' ## my client secret client_secret = 'aNeJpd53jTw...............76dg' ## my client secret access_token = get_access_token(client_id, client_secret) Test_notification = test_notification(access_token) print(Test_notification)
我的Webhook端点处理代码(PHP):
<?php http_response_code(200); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: POST, GET, OPTIONS"); header("Access-Control-Allow-Headers: Content-Type, Authorization"); header("Content-Type: application/json"); $method = $_SERVER['REQUEST_METHOD']; $headers = getallheaders(); file_put_contents("headers.log", date("Y-m-d H:i:s") . " -" . print_r($headers, true) . PHP_EOL, FILE_APPEND); if ($method === 'POST') { $json_data = file_get_contents('php://input'); file_put_contents("webhook_log.log", date("Y-m-d H:i:s") . " - " . $json_data . PHP_EOL, FILE_APPEND); $decoded_data = json_decode($json_data, true); if ($decoded_data === null) { file_put_contents("webhook_log.log", date("Y-m-d H:i:s") . " - JSON Decode Error: " . json_last_error_msg() . PHP_EOL, FILE_APPEND); http_response_code(400); echo json_encode(["error" => "Invalid JSON received", "details" => json_last_error_msg()]); exit; } http_response_code(200); echo json_encode(["message" => "Webhook received successfully"]); exit; } else { http_response_code(200); echo json_encode(["msg" => "This Is Get Method"]); exit; } ?>
错误日志:
2025-02-04 07:36:24,728 - DEBUG - Starting new HTTPS connection (1): marketplace.walmartapis.com:443 2025-02-04 07:36:25,238 - DEBUG - https://marketplace.walmartapis.com:443 "POST /v3/token HTTP/1.1" 200 751 2025-02-04 07:36:25,240 - INFO - Sending Walmart webhook test notification 2025-02-04 07:36:25,240 - DEBUG - URL: https://marketplace.walmartapis.com/v3/webhooks/test 2025-02-04 07:36:25,240 - DEBUG - Headers: { "Accept": "application/json;", "Content-Type": "application/json;", "WM_SEC.ACCESS_TOKEN": "eyJraWQiOiI1NmE2YzVjMy03NTI4LTQ1Y2EtYWMwZC1iNjAzOTJiYzg5YjAiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..-fsXViqo7HDw1Ej8.Y7OqtUEuMtsWaWJWBh....", "WM_SVC.NAME": "Walmart Marketplace", "WM_QOS.CORRELATION_ID": "vemutriruvelganuku6arksogaueora6" } 2025-02-04 07:36:25,241 - DEBUG - Payload: { "eventType": "OFFER_UNPUBLISHED", "eventVersion": "V1", "resourceName": "ITEM", "eventUrl": "https://example.com/price-track/wm_test/wb_test.php", "headers": { "content-type": "application/json;" } } 2025-02-04 07:36:25,242 - DEBUG - Starting new HTTPS connection (1): marketplace.walmartapis.com:443 2025-02-04 07:36:28,727 - DEBUG - https://marketplace.walmartapis.com:443 "POST /v3/webhooks/test HTTP/1.1" 400 190 2025-02-04 07:36:28,729 - INFO - Response Status Code: 400 2025-02-04 07:36:28,729 - DEBUG - Response Headers: {'Accept-Ranges': 'bytes', 'Content-Type': 'application/json', 'Last-Modified': 'Tue, 04 Feb 2025 12:36:28 GMT', 'Vary': 'Origin,Access-Control-Request-Method,Access-Control-Request-Headers', 'X-Envoy-Upstream-Service-Time': '3189', 'X-Tb': '1', 'X-Tb-Optimization-Total-Bytes-Saved': '0', 'Content-Length': '190', 'Expires': 'Tue, 04 Feb 2025 12:36:28 GMT', 'Cache-Control': 'max-age=0, no-cache, no-store', 'Pragma': 'no-cache', 'Date': 'Tue, 04 Feb 2025 12:36:28 GMT', 'Connection': 'close'} 2025-02-04 07:36:28,729 - DEBUG - Response Text: {"errors":{"error":{"severity":"ERROR","description":"EventUrl (https://example.com/price-track/wm_test/wb_test.php) validation failed with http response code : 500","category":"DATA"}}} 2025-02-04 07:36:28,730 - ERROR - Error Response JSON: { "errors": { "error": { "severity": "ERROR", "description": "EventUrl (https://example.com/price-track/wm_test/wb_test.php) validation failed with http response code : 500", "category": "DATA" } } }
我现在不知道该怎么继续排查这个问题了,能不能请大家给我一些指导,说说可能的错误原因和解决步骤呀?
提前谢谢大家的帮助!
备注:内容来源于stack exchange,提问作者Bala2125
相关产品推荐
相关产品推荐

