简体   繁体   English

将 Subprocess.Run 与 BigQuery 的 bq 负载一起使用时出现致命命令错误

[英]Fatal Command error when using Subprocess.Run with bq load for BigQuery

I'm new to python, and i'm trying to ingest a CSV file in Bigquery, using subprocess.run and the bq load util.我是 python 的新手,我正在尝试使用 subprocess.run 和 bq load util 在 Bigquery 中摄取 CSV 文件。

If I write the same command in a shell (windows), it works like a sharm.如果我在 shell(windows)中编写相同的命令,它就像一个沙姆一样工作。 But when I try to use it in python, I get an error.但是当我尝试在 python 中使用它时,我得到一个错误。

This is the code I'm using:这是我正在使用的代码:


# run() returns a CompletedProcess object if it was successful
# errors in the created process are raised here too

command= r'load --project_id=the_projectid_goes_here --source_format=CSV --skip_leading_rows=1 DataSet.TestTable gs://bucket/folder1/folder2/File.csv C:\Users\Username\Folder\File.json'

process = subprocess.run(['bq', command], shell=True, stdout=subprocess.PIPE)

And this is the error:这是错误:

FATAL Command 'load --project_id=the_projectid_goes_here --source_format=CSV --skip_leading_rows=1 DataSet.TestTable gs://bucket/folder1/folder2/File.csv C:\Users\Username\Folder\File.json' unknown
Run 'bq.py help' to get help

Any idea about what is the trouble?知道有什么问题吗?

Thanks!谢谢!

If I pass the same command but as a list, it works:如果我传递相同的命令但作为列表,它可以工作:



comma3=[]
comma3.append(r'--project_id=the_projectid_goes_here ')
comma3.append(r'--source_format=CSV ')
comma3.append(r'--skip_leading_rows=1 )
comma3.append(r'DataSet.TestTable ')
comma3.append(r'gs://bucket/folder1/folder2/File.csv ')
comma3.append(r'C:\Users\Username\Folder\File.json')

process = subprocess.run(['bq','load',comma3], shell=True, stdout=subprocess.PIPE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM