python - 在 python 和 raspberry 中看不到随 post 请求发送的 json 内容
问题描述
我尝试将 json 从树莓派 Pi4 发送到 Laravel 项目,但是当我尝试显示 Json 的内容时,我什么也看不到,只有一个空方括号 []
Python 代码形式为 raspberry :此函数从文件中读取并将其转换为 json 文件并将其发送到 Laravel:
def readFile():
with open("/home/pi/Desktop/Progetti SIoTD/device.txt", "r") as file:
for i in file:
line, *lines = i.split()
if line in mac_dict:
mac_dict[line] += lines
else:
mac_dict[line] = lines
print(mac_dict)
print("\n")
json_obj = json.dumps(mac_dict, indent=4)
with open("/home/pi/Desktop/Progetti SIoTD/Bluetooth/mac_addr.json", "w") as json_file:
json_file.write(json_obj)
print(json_obj)
ip = 'http://192.168.1.6:14000'
headers = {'Content-Type': 'application/json'}
req = requests.post(ip, headers=headers, data=json_obj)
Laravel 控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DictionaryController extends Controller
{
public function index()
{
//
}
public function store(Request $request)
{
return response()->json($request->all());
}
public function show($id)
{
//
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
}
Laravel 路由接口
Route::get('dictionary', [DictionaryController::class, 'store'])->name('dict');
我怎样才能解决这个问题?
解决方案
推荐阅读
- if-statement - 计算某些列中满足任何条件的行数(类似 OR 的操作)
- export - 如何将 Jexcel 表导出到 .csv 和 .xls?
- python - Web 或代理服务器可以在没有 User-Agent 的情况下检测请求者的操作系统吗?
- javascript - 如果在创建新文档时有一个抛出异常,则回滚两个文档中的持久性?
- python - 将 sounddevice 导入 python 崩溃
- python - 根据指定列中的字符串值条目是否包含子字符串来分隔熊猫数据框
- python-3.x - IDLE 表示每个打印语句末尾的双引号是无效的语法。怎么了?
- mysql - MySql 备份最近更新/插入的数据
- docker - 两个 docker 容器无法通信
- github - github 操作 - npm 安装失败,退出代码 1