我有大部分这个应用程序运行顺利我试图让这个python代码发送串行数据,但我总是得到404当我尝试使用python3我得到了serialutil的问题,因为basetring没有被定义等等等在串行库中。所以我回到python 2.7并且想知道是否有可能将https添加到某个地方的字符串中以覆盖正在发生的将其恢复为http的内容?
import serial
import time
import requests
import json
firebase_url = 'https://ourfleet.firebaseio.com'
auth_token = '0sBNZjz4uQvLteDoGSAJSKSDKSDBNASASJSDL'
#Connect to Serial Port for communication
ser = serial.Serial('/dev/tty.wchusbserial410', 9600, timeout=0)
#Setup a loop to send GPS values at fixed intervals
#in seconds
fixed_interval = 10
while 1:
try:
#GPS value obtained from Arduino + Ublox
gps_c = ser.readline()
#current time and date
time_hhmmss = time.strftime('%H:%M:%S')
date_mmddyyyy = time.strftime('%d/%m/%Y')
#current location name
gps_location = 'ourfleet'
print (gps_c + ',' + time_hhmmss + ',' + date_mmddyyyy + ',' + gps_location)
#insert record
data = {'date':date_mmddyyyy,'time':time_hhmmss,'location':gps_c}
result = requests.post('https://ourfleet.firebaseio.com' + '/' + gps_location + '/gps_c.json'+ auth_token, data=json.dumps(data))
#insert record
print ('Record inserted. Result Code = ' + str(result.status_code) + ',' + result.text)
time.sleep(fixed_interval)
except IOError:
print('Error! Something went wrong.')
time.sleep(fixed_interval)