问题描述
我正在为esp8266(运行micropython)编写一组函数,以通过urequests
将数据发送到服务器,但是无法将这些函数导入到我的main.py中。我已经成功创建了用于其他任务的模块并将其导入,但是当我在netclient.py
import urequests
def postData(data_dict,url="http://192.168.1.1:9000/weather_station"):
try:
response = urequests.post(url,headers = {'Connection': 'Close','content-type': 'application/json'},json = data_dict)
except OSError as e:
print("Error sending packet: {} \n retrying...".format(e))
try:
response = urequests.post(url,headers={'Connection': 'Close',json = data_dict)
except OSError as e:
print("Error sending packet: {} \n retry Failed".format(e))
response = False
return response
然后当我从webrepl尝试此操作
import netclient
netclient.postData()
我明白了
Traceback (most recent call last):
File "<stdin>",line 1,in <module>
AttributeError: 'module' object has no attribute 'postData'
当我检查netclient
时,它的唯一属性是__class__
和__name__
我要去哪里错了?
文件系统如下
import os
os.listdir()
['boot.py','credentials.json','netclient.py','lib','main.py','sensors.py','webrepl_cfg.py','wifi.py']
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)