[英]TypeError: expected str, bytes or os.PathLike object, not list convert
[英]Python code working on one computer, but not other: “expected str, bytes or os.PathLike object, not list”
我正在運行此代碼以使用來自 GSUtils 的 subprocess 和 bq 命令從 Google Big Query 獲取表列表。 出於某種我不明白的原因,它在一台計算機上工作(Python 3.8.6),但在另一台計算機上(Python 3.8.7)我收到下面發布的錯誤。
代碼有什么問題?
謝謝!
import subprocess
import re
params=[]
params.append("--use_legacy_sql=false ")
params.append(r"SELECT table_name FROM Exportar_CSV.INFORMATION_SCHEMA.TABLES WHERE table_schema IN ('Exportar_CSV')")
process = subprocess.run(['bq','query',params], shell=True, capture_output=True)
output = process.stdout.decode("utf-8")
#Convert the output to a list type.
table_list=output.split("\r\n")
table_list=[item.strip("|").strip() for item in table_list]
table_list= [ item for item in table_list if "table_name" not in item and "+--------" not in item and '' != item]
這是 python 拋出的錯誤:
Traceback (most recent call last):
File "Export_to_CSV.py", line 8, in <module>
process = subprocess.run(['bq','query',params], shell=True, capture_output=True)
File "C:\Python\lib\subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python\lib\subprocess.py", line 1247, in _execute_child
args = list2cmdline(args)
File "C:\Python\lib\subprocess.py", line 549, in list2cmdline
for arg in map(os.fsdecode, seq):
File "C:\Python\lib\os.py", line 818, in fsdecode
filename = fspath(filename) # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not list
正如盧克伍德沃德所說,似乎參數是列表中的列表。 所以改變這一點,它對兩者都有效。 仍然不知道為什么它在一台計算機上工作......
params=[]
params.append(str("bq"))
params.append(str("query"))
params.append(str("--use_legacy_sql=false"))
params.append(str(r"SELECT table_name FROM Exportar_CSV.INFORMATION_SCHEMA.TABLES WHERE table_schema IN ('Exportar_CSV')"))
process = subprocess.run(params, shell=True, capture_output=True)
output = process.stdout.decode("utf-8")
#Convert the output to a list type.
table_list=output.split("\r\n")
table_list=[item.strip("|").strip() for item in table_list]
table_list= [ item for item in table_list if "table_name" not in item and "+--------" not in item and '' != item]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.