我現在的python腳本:類型錯誤:需要一個浮動PYTHON
import ftplib
import hashlib
import httplib
import pytz
from datetime import datetime
import urllib
from pytz import timezone
import os.path, time
import glob
def ftphttp():
dataset_path='Desktop'
files = glob.glob(dataset_path+"/images/*.png")
ts = files.sort(key=os.path.getmtime)
dt = datetime.fromtimestamp(ts, pytz.utc)
timeZone= timezone('Asia/Singapore')
localtime = dt.astimezone(timeZone).isoformat()
cam = "002"
lscam = localtime + cam
ftp = ftplib.FTP('localhost','kevin403','S$ip1234')
ftp.cwd('/var/www/html/image')
m=hashlib.md5()
m.update(lscam)
dd=m.hexdigest()
for image in glob.glob(os.path.join('Desktop/images/*.png')):
with open(image, 'rb') as file:
ftp.storbinary('STOR '+dd+ '.png', file)
x = httplib.HTTPConnection('localhost', 8086)
x.connect()
f = {'ts' : localtime}
x.request('GET','/camera/store?cam='+cam+'&'+urllib.urlencode(f)+'&fn='+dd)
y = x.getresponse()
z=y.read()
x.close()
ftp.quit()
的引用:
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
ftphttp()
File "/home/kevin403/Testtimeloop.py", line 17, in ftphttp
dt = datetime.fromtimestamp(ts, pytz.utc)
TypeError: a float is required
我試圖讓一個文件夾中的文件列表,以獲得他們的修改時間戳和商店它在一個數據庫中。但我似乎無法做到。任何人都知道如何做到這一點?一直試用它很長時間,我是新來的蟒蛇。
不相關,但強烈建議切換到標準4空格縮進... – Julien