I'm using the google-api-python-client library to upload apks to Google Playstore. All worked well until today. I did not modify my upload script but now i am getting the error:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/androidpublisher/v3/applications/[packageName]/edits/[editId]/tracks/internal?alt=json returned
**"Track names in request path and request body must match."**
This is my upload script:
from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client.service_account import ServiceAccountCredentials
import json
import mimetypes
package_name = '...'
keyfile_content = '...'
apk_file = '...'
release_name = '...'
track = 'internal'
mimetypes.add_type("application/octet-stream", ".apk")
mimetypes.add_type("application/octet-stream", ".aab")
keyfile_dict = json.loads(keyfile_content)
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, 'https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
apk_response = service.edits().apks().upload(
editId=edit_id,
packageName=package_name,
media_body=apk_file).execute()
print('Version code %d has been uploaded but not yet committed' % apk_response['versionCode'])
if track:
track_response = service.edits().tracks().update(
editId=edit_id,
track=track,
packageName=package_name,
body={u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
}]}).execute()
print('Track %s is set with releases: %s' % (
track_response['track'], str(track_response['releases'])))
else:
print('No track specified')
commit_request = service.edits().commit(
editId=edit_id, packageName=package_name).execute()
print('Edit "%s" has been committed' % commit_request['id'])
I am using google-api-python-client 1.7.11.
I could not find anything about the error online. Has anyone here an idea?
Update
Thanks to the reply from @Silvio i could get my script to work again by adding the track to the request body as well:
from apiclient.discovery import build
import httplib2
from oauth2client import client
from oauth2client.service_account import ServiceAccountCredentials
import json
import mimetypes
package_name = '...'
keyfile_content = '...'
apk_file = '...'
release_name = '...'
track = 'internal'
mimetypes.add_type("application/octet-stream", ".apk")
mimetypes.add_type("application/octet-stream", ".aab")
keyfile_dict = json.loads(keyfile_content)
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, 'https://www.googleapis.com/auth/androidpublisher')
http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
edit_request = service.edits().insert(body={}, packageName=package_name)
result = edit_request.execute()
edit_id = result['id']
apk_response = service.edits().apks().upload(
editId=edit_id,
packageName=package_name,
media_body=apk_file).execute()
print('Version code %d has been uploaded but not yet committed' % apk_response['versionCode'])
if track:
track_response = service.edits().tracks().update(
editId=edit_id,
track=track,
packageName=package_name,
body={u'track': track,
u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
}]}).execute()
print('Track %s is set with releases: %s' % (
track_response['track'], str(track_response['releases'])))
else:
print('No track specified')
commit_request = service.edits().commit(
editId=edit_id, packageName=package_name).execute()
print('Edit "%s" has been committed' % commit_request['id'])
Add "track" to the request body as well.
e.g.
body={u'track': track,
u'releases': [{
u'name': release_name,
u'versionCodes': [str(apk_response['versionCode'])],
u'status': u'completed',
...
This worked for me. You can check the expected request body structure here:
https://developers.google.com/android-publisher/api-ref/edits/tracks#resource
I'm having similar problems publishing with Codemagic Google Play publishing fails with "Track names in request path and request body must match", looks like something might be wrong on Google's side
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With