![](/img/trans.png)
[英]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.