{"action":"created","issue":{"url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/605","repository_url":"https://api.github.com/repos/googleapis/google-api-python-client","labels_url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/605/labels{/name}","comments_url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/605/comments","events_url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/605/events","html_url":"https://github.com/googleapis/google-api-python-client/issues/605","id":391229314,"node_id":"MDU6SXNzdWUzOTEyMjkzMTQ=","number":605,"title":"Batch request for oauth2 token requests returns 400 Bad Request error","user":{"login":"SwapnaReddyL","id":44005986,"node_id":"MDQ6VXNlcjQ0MDA1OTg2","avatar_url":"https://avatars3.githubusercontent.com/u/44005986?v=4","gravatar_id":"","url":"https://api.github.com/users/SwapnaReddyL","html_url":"https://github.com/SwapnaReddyL","followers_url":"https://api.github.com/users/SwapnaReddyL/followers","following_url":"https://api.github.com/users/SwapnaReddyL/following{/other_user}","gists_url":"https://api.github.com/users/SwapnaReddyL/gists{/gist_id}","starred_url":"https://api.github.com/users/SwapnaReddyL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SwapnaReddyL/subscriptions","organizations_url":"https://api.github.com/users/SwapnaReddyL/orgs","repos_url":"https://api.github.com/users/SwapnaReddyL/repos","events_url":"https://api.github.com/users/SwapnaReddyL/events{/privacy}","received_events_url":"https://api.github.com/users/SwapnaReddyL/received_events","type":"User","site_admin":false},"labels":[{"id":944893201,"node_id":"MDU6TGFiZWw5NDQ4OTMyMDE=","url":"https://api.github.com/repos/googleapis/google-api-python-client/labels/type:%20question","name":"type: question","color":"c5def5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-12-14T19:04:12Z","updated_at":"2018-12-19T15:15:37Z","closed_at":null,"author_association":"NONE","body":"I'm using **google api client 1.7.4** with **python 2.7** and unable to make successful batch requests with new_batch_http_request api. I keep getting **400 Bad Request** error\r\n\r\nAfter debugging google api client lib, final request body is following :\r\n\r\n`--===============6159072106655335965==\r\nContent-Type: application/http\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: binary\r\nContent-ID: <943c8367-618b-4817-97d1-fe4f4005af25+0AL0173QlVaLoUk9PVA%40%40%3F%7C%3F%40%40administrator%40testcloudlockprimary1.com>\r\n\r\nPOST /oauth2/v4/token HTTP/1.1\r\nContent-Type: application/json; charset=utf-8\r\nMIME-Version: 1.0\r\nHost: www.googleapis.com\r\ncontent-length: 715\r\n\r\ngrant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9vYXV0aDIvdjQvdG9rZW4iLCJleHAiOjE1NDQ4MTAzMDcsImlhdCI6MTU0NDgwNjcwNywiaXNzIjoiNjM1MjU5ODkwMTUwLWZyam5iYjdjcDFvNHAwbDBjdDRuc3BhaDEzZG5qZjQzQGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29tIiwic2NvcGUiOiJodHRwczovL3d3dy5nb29nbGVhcGlzLmNvbS9hdXRoL2RyaXZlIiwidG9rZW5fdXJpIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YzL3Rva2VuIiwic3ViIjoiYWRtaW5pc3RyYXRvckB0ZXN0Y2xvdWRsb2NrcHJpbWFyeTEuY29tIn0.deaW9w-023-ZABfsftAuXdvwyMp-joZSoVgakKfsOhR89hhi8yRocpqK8YXmL7kvpEyaqLEU3dRyQRJU7XFpexCUYZpM4TC8KKsaeTakENADjdFPZw8QHgsRxUz4iAFM6Lt3Ru0HJRwkQDPfVfyX0k6i0BI46fUIOVd91jiHJ-0\r\n--===============6159072106655335965==--\r\n`\r\n\r\n**Here is what code looks like :** \r\n###code to build batch request and nested requests#######\r\n` logger.info('Refreshing credentials for %s users', len(creds_to_refresh))\r\n        \r\n       oauth_service = build('oauth2', 'v2', http=LoggingHttp())\r\n        batch_request = oauth_service.new_batch_http_request()\r\n \r\n        for request_id, creds in six.iteritems(credentials_to_refresh):\r\n            request = build_token_request(creds)\r\n            batch_request.add(request, request_id=request_id)\r\n\r\n        batch_request.execute()\r\n\r\n       def build_token_request(creds):\r\n            request = HttpRequest(http=LoggingHttp(), postproc=_postproc,\r\n                          uri=creds.token_uri,\r\n                          method='POST',\r\n                          body=creds._generate_request_body(),\r\n                          headers=creds._generate_request_headers())\r\n             return request\r\n\r\n###methods generating request body and headers###\r\n          \r\n           def _generate_request_body(self):\r\n                 assertion = self._generate_assertion()\r\n                 body = urllib.parse.urlencode({\r\n                     'assertion': assertion,\r\n                      'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',\r\n                 })\r\n              return body\r\n\r\n         def _generate_request_headers(self):\r\n               \"\"\"Generate the headers that will be used in the refresh request.\"\"\"\r\n                   headers = {\r\n                                 'content-type': 'application/json; charset=utf-8',\r\n                             }\r\n                  if self.user_agent is not None:\r\n                  headers['user-agent'] = self.user_agent\r\n           return headers\r\n\r\n`"},"comment":{"url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/comments/448630543","html_url":"https://github.com/googleapis/google-api-python-client/issues/605#issuecomment-448630543","issue_url":"https://api.github.com/repos/googleapis/google-api-python-client/issues/605","id":448630543,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODYzMDU0Mw==","user":{"login":"SwapnaReddyL","id":44005986,"node_id":"MDQ6VXNlcjQ0MDA1OTg2","avatar_url":"https://avatars3.githubusercontent.com/u/44005986?v=4","gravatar_id":"","url":"https://api.github.com/users/SwapnaReddyL","html_url":"https://github.com/SwapnaReddyL","followers_url":"https://api.github.com/users/SwapnaReddyL/followers","following_url":"https://api.github.com/users/SwapnaReddyL/following{/other_user}","gists_url":"https://api.github.com/users/SwapnaReddyL/gists{/gist_id}","starred_url":"https://api.github.com/users/SwapnaReddyL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SwapnaReddyL/subscriptions","organizations_url":"https://api.github.com/users/SwapnaReddyL/orgs","repos_url":"https://api.github.com/users/SwapnaReddyL/repos","events_url":"https://api.github.com/users/SwapnaReddyL/events{/privacy}","received_events_url":"https://api.github.com/users/SwapnaReddyL/received_events","type":"User","site_admin":false},"created_at":"2018-12-19T15:15:37Z","updated_at":"2018-12-19T15:15:37Z","author_association":"NONE","body":"@busunkim96 thanks for information. But nested requests in batch does use token_endpoint \"POST /oauth2/v4/token HTTP/1.1\" . Is the oauth2 service **build('oauth2', 'v2', http=LoggingHttp())** right batch service for nested token requests?"}}
{"actor":{"display_login":"SwapnaReddyL"}}