0

我正在使用 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 错误。

有没有人遇到过这样的事情?知道是什么原因造成的吗?

谢谢!

4

1 回答 1

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 '\')或者它尝试写入或读取的路径不可访问。(或者可能它写入的路径与它下次尝试读取的路径不匹配)。

于 2013-10-20T21:30:59.617 回答