0

Information gleamed from here.

Given that I have a ACCESS_TOKEN and a APP_ID, I should be able to update a chrome extension using the following.

r = requests.put(
   'https://www.googleapis.com/upload/chromewebstore/v1.1/items/%s' % APP_ID,
   headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
            'x-goog-api-version': "2"},
   files={'file': open('target_extension.crx', 'rb')})
print r.text

Prints:

{"error":{"errors":[{"domain":"global","reason":"notUpload","message":"Not an upload request. Re-send request to: https://www.googleapis.com/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}],"code":400,"message":"Not an upload request. Re-send request to: https://www.googleapis.com/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}}

Ok, seems clear enough, I switch the url:

r = requests.put(
    'https://www.googleapis.com/chromewebstore/v1.1/items/%s' % APP_ID,
    headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
             'x-goog-api-version': "2"},
    files={'file': open('target_extension.crx', 'rb')})
print r.text

Prints:

{"error":{"errors":[{"domain":"global","reason":"wrongUrlForUpload","message":"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}],"code":400,"message":"Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/chromewebstore/v1.1/items/fmcklaikklmlfahjgdndacebapkpefan"}}

So one says I am not a upload, switch. And the other one says I am a upload, switch back. What am I doing wrong here?

Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86
  • I'm not familiar with this python library, but [apparently](https://stackoverflow.com/a/11833013) you need to use `data` key for files in PUT request. – wOxxOm Mar 11 '17 at 21:19

1 Answers1

1

Whelp, thanks to wOxxOm's comment, I was able to figure this out. Also, turns out I was supposed to be uploading a zip, not a crx.

filepath = 'target_extension.zip'
with open(filepath, 'rb') as fh:
    resp = requests.put(
       'https://www.googleapis.com/upload/chromewebstore/v1.1/items/%s' % APP_ID,
       data=fh.read(),
       headers={'Authorization': "Bearer %s" % ACCESS_TOKEN,
                                 'x-goog-api-version': "2"},
       params={'file': filepath})
Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86