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

使用Python requests库向NiFi发送数据失败,寻求技术协助

Troubleshooting NiFi ListenHTTP Not Receiving Data from Python Requests

Let's work through this step by step to get your data flowing into NiFi. Here are the most common fixes and checks:

1. Fix Your Python Request First

Your current code serializes JSON but doesn't explicitly tell NiFi what type of data you're sending—this is likely the biggest blocker. NiFi's ListenHTTP relies on clear content type headers to properly parse incoming payloads.

Use requests built-in json parameter, which automatically handles serialization and sets the correct Content-Type: application/json header for you:

import requests

url = 'http://dev.test.com:7001/contentListener'
payload = {'some': 'data'}
r = requests.post(url, json=payload)

# Add these lines to debug the response
print(f"Status Code: {r.status_code}")
print(f"Response Text: {r.text}")

Updated Code Option 2 (Manual Header Approach)

If you prefer to keep using json.dumps(), explicitly set the content type header to let NiFi know you're sending JSON:

import requests
import json

url = 'http://dev.test.com:7001/contentListener'
payload = {'some': 'data'}
headers = {'Content-Type': 'application/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)

# Debug output to see what NiFi sends back
print(f"Status Code: {r.status_code}")
print(f"Response Text: {r.text}")

The debug prints will immediately flag issues like 404 (wrong path), 405 (method not allowed), or 500 (server error)—these will point us straight to the next set of checks.

2. Verify NiFi ListenHTTP Configuration

Since you didn't share your component settings, here are the critical ones to double-check:

  • Listening Port: Confirm it's set to 7001—mismatched ports are a super frequent culprit.
  • Context Path: In the HTTP Context Map configuration, make sure the Context Path is exactly /contentListener (including the leading slash). If you leave this blank, your request URL should be http://dev.test.com:7001 instead.
  • Allowed HTTP Methods: Ensure POST is included in this field. By default, some NiFi versions only allow GET—add POST (comma-separated, e.g., GET,POST) to enable receiving POST requests.
  • Component State: Make sure the ListenHTTP processor is in the RUNNING state (not stopped or disabled). Check the NiFi UI for any error icons next to the component.

3. Debug & Validate in NiFi

To confirm if data is coming in (even if you can't see it yet):

  1. Add a LogAttribute processor to your flow.
  2. Connect the success relationship from ListenHTTP to LogAttribute.
  3. Configure LogAttribute to log all attributes (set "Attributes to Log" to *).
  4. Run the flow and send your Python request—check the NiFi logs (or the LogAttribute's output) for incoming request details like headers, content length, and payload.

4. Network & Permissions Checks

  • Confirm the machine running your Python script can reach the NiFi server: Try pinging dev.test.com or using telnet dev.test.com 7001 to verify the port is open.
  • Check NiFi's nifi-app.log (usually in the nifi/logs directory) for errors like "path not found" or "method not allowed"—these will give direct clues about what's misconfigured.

Once you fix the content type header and verify the NiFi settings, your data should start flowing through!

内容的提问来源于stack exchange,提问作者amira khalifa

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:23:33