[英]I'm having problem looping through Upload file in Python?
當我執行此代碼時:
uploaded_file_info = ol.upload_file(c:\video\file.mp4)
print(uploaded_file_info)
它很好用
但是,當我嘗試從CSV文件循環時,出現以下錯誤:
碼:
with open('ListTest.1.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader)
for line in csv_reader:
print(line)
name = (line[0])
VidPath = (line[4])
print(name)
print(VidPath)
uploaded_file_info = ol.upload_file(VidPath)
print(uploaded_file_info)
追溯 :
Traceback (most recent call last):
File "PrintingTest.py", line 19, in <module>
uploaded_file_info = ol.upload_file(VidPath)
File "C:\Users\resta\Anaconda3\lib\site-packages\openload\openload.py", line 258, in upload_file
files={'upload_file': open(file_path, 'rb')}).json()
OSError: [Errno 22] Invalid argument: ' c:\video\file.mp4'
我究竟做錯了什么?
看起來您的錯誤消息中字符串的開頭有一個空格。 查看.strip()是否通過更改來修復它:
uploaded_file_info = ol.upload_file(VidPath)
至
uploaded_file_info = ol.upload_file(VidPath.strip())
您可能想以其他方式修復它,但是如果空間引起了錯誤,這將立即告訴您。
注意路徑前面的空間。 ' c:\\video\\file.mp4'
。 您的csvreader在','
(逗號)而不是', '
(逗號空間)上分割。 將正確的定界符傳遞給reader
函數或在第[4]行上使用字符串函數strip
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.