2013-08-06 28 views
0

我嘗試使用示例架構和一些示例數據從Perl上傳到BigQuery。我在他們提供的文檔之後遇到了死衚衕,所以現在我試圖模仿bq命令行客戶端成功執行的操作。無法從Perl上傳到BigQuery

我跟蹤bq通過在中向request方法添加調試print (method, uri, headers, body)來確定。我通過對響應執行Dumper來跟蹤我的Perl庫正在做什麼,其中還包括我發送的_requestbq中的模式是他們POST到一個上傳的URL,然後找到locationPUT數據到。通過一系列的GET請求監視相應的作業,最後他們做出迴應。

在Perl中,我的POST成功,我的GET失敗,並且Invalid Upload Request(但沒有提示它爲什麼無效)。我想弄清楚兩者之間有什麼區別可以解釋我的失敗。但我找不到它。

這裏是(access_token,IP地址和project_id消失)我得到的痕跡。

對於POST從Python的信息是:

(
    u'POST', 
    u'https://www.googleapis.com/upload/bigquery/v2/projects/<project ID>/jobs?uploadType=resumable&alt=json', 
    { 
     'content-length': '442', 
     'accept-encoding': 'gzip, deflate', 
     'accept': 'application/json', 
     'user-agent': u'bq/2.0 google-api-python-client/1.0', 
     'X-Upload-Content-Length': '84', 
     'X-Upload-Content-Type': 'application/octet-stream', 
     'content-type': 'application/json', 
     'Authorization': u'Bearer <access token>' 
    }, 
    '{"configuration": {"load": {"sourceFormat": "NEWLINE_DELIMITED_JSON", "destinationTable": {"projectId": "<project id>", "tableId": "demo_api", "datasetId": "tmp_bt"}, "maxBadRecords": 0, "schema": {"fields": [{"type": "STRING", "mode": "required", "name": "demo_string"}, {"type": "INTEGER", "mode": "required", "name": "demo_integer"}]}}}, "jobReference": {"projectId": "<project id>", "jobId": "bqjob_r139e633b7e522cf7_0000014031d9fb49_1"}}' 
) 

相應的Perl得到一個明顯成功的響應對象(其中你可以看到_request)的:

$VAR1 = bless({ 
    '_protocol' => 'HTTP/1.1', 
    '_content' => '', 
    '_rc' => '200', 
    '_headers' => bless({ 
     'connection' => 'close', 
     'client-response-num' => 1, 
     'location' => 'https://www.googleapis.com/upload/bigquery/v2/projects/<project id>/jobs?uploadType=resumable&upload_id=AEnB2Ur0mdwmZpMot6ftkgj1IkqK0f7oPbZrXWQekUDHK_E2o2HKznJO6DK2xPYCB-nhUGrMrEJJ7z1Tz9Crnka9e5EYGP1lWQ', 
     'date' => 'Tue, 06 Aug 2013 20:46:05 GMT', 
     'client-ssl-cert-issuer' => '/C=US/O=Google Inc/CN=Google Internet Authority', 
     'client-ssl-cipher' => 'RC4-SHA', 
     'client-peer' => '<some ip>:443', 
     'content-length' => '0', 
     'client-date' => 'Tue, 06 Aug 2013 20:46:05 GMT', 
     'content-type' => 'text/html; charset=UTF-8', 
     'client-ssl-cert-subject' => '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com', 
     'server' => 'HTTP Upload Server Built on Jul 24 2013 17:20:01 (1374711601)', 
     'client-ssl-socket-class' => 'IO::Socket::SSL' 
    }, 'HTTP::Headers'), 
    '_msg' => 'OK', 
    '_request' => bless({ 
     '_content' => '{"configuration":{"load":{"maxBadRecords":0,"destinationTable":{"datasetId":"tmp_bt","tableId":"perl","projectId":<project id>},"sourceFormat":"NEWLINE_DELIMITED_JSON","schema":{"fields":[{"mode":"required","name":"demo_string","type":"STRING"},{"mode":"required","name":"demo_integer","type":"INTEGER"}]}}},"jobReference":{"projectId":<project id>,"jobId":"perlapi_1375821964"}}', 
     '_uri' => bless(do{\(my $o = 'https://www.googleapis.com/upload/bigquery/v2/projects/<project id>/jobs?uploadType=resumable')}, 'URI::https'), 
     '_headers' => bless({ 
      'user-agent' => 'libwww-perl/6.05', 
      'content-type' => 'application/json', 
      'accept' => 'application/json', 
      ':X-Upload-Content-Type' => 'application/octet-stream', 
      'content-length' => 379, 
      ':X-Upload-Content-Length' => '84', 
      'authorization' => 'Bearer <access token>' 
     }, 'HTTP::Headers'), 
     '_method' => 'POST', 
     '_uri_canonical' => $VAR1->{'_request'}{'_uri'} 
    }, 'HTTP::Request') 
}, 'HTTP::Response'); 

然後我們有一個PUT。在Python端我們發出:

(
    'PUT', 
    'https://www.googleapis.com/upload/bigquery/v2/projects/<project id>/jobs?uploadType=resumable&alt=json&upload_id=AEnB2UpWMRCAOffqyR0d7zvGVtD-KWhrC9jGB-q_igecJgoyz_mIHgEFfs9cYoPxUwUxuflQScMzGxDsKKJ_CJPQq4Os-AkdZA', 
    { 
     'Content-Range': 'bytes 0-83/84', 
     'Content-Length': '84', 
     'Authorization': u'Bearer <access token>', 
     'user-agent': u'bq/2.0' 
    }, 
    <apiclient.http._StreamSlice object at 0x10ce11150> 
) 

(我已經驗證該流切片對象具有相同的84個字節的Perl。)這裏是Perl失敗:

$VAR1 = bless({ 
    '_protocol' => 'HTTP/1.1', 
    '_content' => '{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "badRequest", 
    "message": "Invalid Upload Request" 
    } 
    ], 
    "code": 400, 
    "message": "Invalid Upload Request" 
} 
} 
', 
    '_rc' => '400', 
    '_headers' => bless({ 
     'connection' => 'close', 
     'client-response-num' => 1, 
     'date' => 'Tue, 06 Aug 2013 20:46:07 GMT', 
     'client-ssl-cert-issuer' => '/C=US/O=Google Inc/CN=Google Internet Authority', 
     'client-ssl-cipher' => 'RC4-SHA', 
     'client-peer' => '<some IP address>:443', 
     'content-length' => '193', 
     'client-date' => 'Tue, 06 Aug 2013 20:46:07 GMT', 
     'content-type' => 'application/json', 
     'client-ssl-cert-subject' => '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.googleapis.com', 
     'server' => 'HTTP Upload Server Built on Jul 24 2013 17:20:01 (1374711601)', 
     'client-ssl-socket-class' => 'IO::Socket::SSL' 
    }, 'HTTP::Headers'), 
    '_msg' => 'Bad Request', 
    '_request' => bless({ 
     '_content' => '{"demo_string":"foo", "demo_integer":"2"} 
{"demo_string":"bar", "demo_integer":"3"} 
', 
     '_uri' => bless(do{\(my $o = 'https://www.googleapis.com/upload/bigquery/v2/projects/<project id>/jobs?uploadType=resumable&upload_id=AEnB2Ur0mdwmZpMot6ftkgj1IkqK0f7oPbZrXWQekUDHK_E2o2HKznJO6DK2xPYCB-nhUGrMrEJJ7z1Tz9Crnka9e5EYGP1lWQ')}, 'URI::https'), 
     '_headers' => bless({ 
      'user-agent' => 'libwww-perl/6.05', 
      ':Content-Length' => '84', 
      ':Content-Range' => '0-83/84', 
      'content-length' => 84, 
      'authorization' => 'Bearer <access token>' 
     }, 'HTTP::Headers'), 
     '_method' => 'PUT', 
     '_uri_canonical' => $VAR1->{'_request'}{'_uri'} 
    }, 'HTTP::Request') 
}, 'HTTP::Response'); 

我應該嘗試在Perl方面做出改變,使BigQuery能夠像我一樣迴應bq

回答

1

你的一些PUT頭有冒號在他們面前,其中Python不會:

':Content-Length' => '84', 
':Content-Range' => '0-83/84', 
+0

這些冒號不會影響我的結果。讓他們告訴HTTP :: Headers不要規範化頭文件的大小寫。我希望能夠像Python一樣強制使用相同的大寫字母,但事實並非如此。 也就是說,如果BigQuery違反了http://www.ietf.org/rfc/rfc2616.txt,使頭文件區分大小寫,那麼我需要一個需要什麼大小寫的列表,在哪裏。 – btilly

0

我懷疑有東西在多載請求格式不正確。錯誤「無效上傳請求」是爲了響應試圖將數據有效載荷分離出多部分MIME消息。您的日誌記錄不包括請求正文的詳細信息,因此我們不能並排比較它們以發現意外的差異。

爲了確保問題是多上傳,你可以嘗試從谷歌存儲,而不是在請求中包括有效載荷本身的數據加載數據加載請求。這將驗證perl api請求路徑正在爲您工作。

FYI:有一個字母的Perl谷歌API客戶端,可以幫助你。我沒有嘗試過,也不知道它是否積極開發,但您可能會發現一些有用的提示。退房https://code.google.com/p/google-api-perl-client/

+0

在Python版本中,Perl中的主體是byte的字節,與httplib2的request請求方法內部的'body'內容相同。你是否建議Python看看它是一個帖子的事實,並在它到達你的服務之前改變它的身體? – btilly

+0

我會看看那個客戶。一目瞭然它是alpha,並且只是最近纔有了對上傳的支持。但值得嘗試。 – btilly