我正在使用BigQuery的命令行工具将数据加载到BigQuery中。
我正在使用以下方法通过C#程序运行bq工具:
private void RunShellCmd(string cmd, string args)
{
ProcessStartInfo start = new ProcessStartInfo
{
FileName = cmd,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true
};
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
if (OnMessage != null)
{
OnMessage(result);
}
}
}
}
cmd 是bq脚本工具的路径, args 是: load --nosync --credential_file = _CRED_PATH_ --source_format = NEWLINE_DELIMITED_JSON --project_id = _PROJECT_ID_ _TABLE_URI_ _DATA_FILE _
从shell执行确切命令时,它可以正常工作。 但是,通过C#程序,我得到以下输出:
Welcome to BigQuery! This script will walk you through the process of initializing your .bigqueryrc configuration file.
First, we need to set up your credentials if they do not already exist.
******************************************************************
** No OAuth2 credentials found, beginning authorization process **
******************************************************************
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery&redirect_uri=...
Enter verification code: You have encountered a bug in the BigQuery CLI. Google engineers monitor and answer questions on Stack Overflow, with the tag google-bigquery: http://stackoverflow.com/questions/ask?tags=google-bigquery Please include a brief description of the steps that led to this issue, as well as the following information:
========================================
== Platform == CPython:2.7.5:Windows-2008ServerR2-6.1.7601-SP1
== bq version == v2.0.16
== Command line == ['C:\\Python27\\Scripts\\bq-script.py', 'load', '--nosync', '--credential_file=C:\\Users\\Administrator\\.bigquery.v2.token', '--source_format=NEWLINE_DELIMITED_JSON', '--project_id=_PROJECT_ID_',
>'_TABLE_URI_', '_DATA_FILE_PATH_']
== UTC timestamp == 2013-10-20 05:52:59
== Error trace == File "build\bdist.win32\egg\bq.py", line 783, in RunSafely
return_value = self.RunWithArgs(*args, **kwds) File "build\bdist.win32\egg\bq.py", line 2082, in RunWithArgs
client = Client.Get() File "build\bdist.win32\egg\bq.py", line 604, in Get
cls.client = Client.Create() File "build\bdist.win32\egg\bq.py", line 584, in Create
credentials = _GetCredentialsFromFlags() File "build\bdist.win32\egg\bq.py", line 390, in _GetCredentialsFromFlags
credentials = credentials_getter(storage) File "build\bdist.win32\egg\bq.py", line 330, in
_GetCredentialsFromOAuthFlow
credentials = oauth2client.tools.run(flow, storage) File "build\bdist.win32\egg\oauth2client\util.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs) File "build\bdist.win32\egg\oauth2client\old_run.py", line 149, in run
code = raw_input('Enter verification code: ').strip()
========================================
Unexpected exception in init operation: EOF when reading a line
Successfully started load _TABLE_URI_
奇怪的是命令实际上正常工作并正确加载数据(最终输出线也证明了这一点)。 但由于某种原因,它之前是OAUTH 2.0错误。
以前有没有人遇到这样的事情? 知道可能导致什么吗?
谢谢!
答案 0 :(得分:0)
为什么要从c#调用bq.py工具而不是使用C#客户端?
c#客户端可在此处获得: https://developers.google.com/api-client-library/dotnet/apis/#BigQuery_API 和ndocs在这里: https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/csharp/latest/annotated.html
如果您不想/不能使用C#客户端,我猜测bq在写出凭证文件(或读取凭证文件)时遇到问题。可能这是由于Windows路径问题('/'vs'\')或者它尝试写入或读取的路径可能无法访问。 (或者它写入的路径可能与下次尝试读取的路径不匹配)。