Cannot upload media bundle using API (code from example)

626 views
Skip to first unread message

Michael Vinogradov

unread,
Jan 8, 2018, 10:33:11 AM1/8/18
to AdWords API Forum

Hi

Need help ! 
I trying upload html5 using API and get error MediaBundleError.INVALID_MEDIA_BUNDLE @ media[0].data.


Code:

$mediaService = $this->googleApiClient->get($this->session, MediaService::class);

// Create HTML5 media and add it to the list.
$html5Zip = new MediaBundle();
$html5Zip->setData(file_get_contents('https://goo.gl/9Y7qI2'));
$html5Zip->setType(MediaMediaType::MEDIA_BUNDLE);
$mediaBundles = [$html5Zip];
// Upload the media bundle to the server.
$result = $mediaService->upload($mediaBundles);


SOAP file in attachment.

Thank you
soap_xml.log

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Jan 8, 2018, 2:27:10 PM1/8/18
to AdWords API Forum
Hi Michael, 

It looks like the media bundle that you are trying to upload has some issues. Could you please follow this guide to validate your media bundle? Once you are able to fix the issues with that, the API call should work fine.

Thanks,
Sreelakshmi, AdWords API Team

Peter Okunev

unread,
Feb 13, 2018, 12:01:05 PM2/13/18
to AdWords API Forum
Hi Sreelakshmi, 

I have exactly the same error on python. 
In both cases me and Michael are using the example of a Media Bundle provided by Google: 'https://goo.gl/9Y7qI2'
I have also tried creating my own simple HTML5 consisting only of an image in Google Web Designer and got same error. 

Mistake response: 

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/peterokunev/PycharmProjects/goeuro/src/projects/display/gdn_creative_manager/scripts/t_html5.py
<suds.sax.document.Document object at 0x1075fddd8>
Response summary - {'requestId': 0005651ad02a66600a379b4379097203, 'responseTime': 297, 'serviceName': MediaService, 'methodName': upload, 'operations': 1, 'isFault': True, 'faultMessage': '[MediaBundleError.INVALID_MEDIA_BUNDLE @ media[0].data]'}
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/util.py", line 123, in PatchedHttpTransportSend
    fp = self.u2open(u2request)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/transport/http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/client.py", line 613, in send
    reply = self.options.transport.send(request)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/util.py", line 134, in PatchedHttpTransportSend
    raise suds.transport.TransportError(e.msg, e.code, e.fp)
suds.transport.TransportError: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/peterokunev/PycharmProjects/goeuro/src/projects/display/gdn_creative_manager/scripts/t_html5.py", line 64, in <module>
    main(adwords_client)
  File "/Users/peterokunev/PycharmProjects/goeuro/src/projects/display/gdn_creative_manager/scripts/t_html5.py", line 43, in main
    response = media_service.upload(media)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/googleads/common.py", line 767, in MakeSoapRequest
    self._packer) for arg in args])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/client.py", line 581, in invoke
    result = self.send(soapenv)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/client.py", line 619, in send
    description=tostr(e), original_soapenv=original_soapenv)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/suds/client.py", line 670, in process_reply
    raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: '[MediaBundleError.INVALID_MEDIA_BUNDLE @ media[0].data]'

Process finished with exit code 1

"""This example uploads an HTML5 zip file.
"""
from src import base_dir, config_chain, key_paths
import base64
import urllib.request
from googleads import adwords

API_VERSION = config_chain["adwords"]["api_version"]
PATH_ADWORDS_CREDENTIALS = key_paths["adwords"]
MAIN_MCC_ID = config_chain["adwords"]["main_client_customer_id"]
TEST_ACCOUNT_ID = config_chain["adwords"]["test_account_id"]


def main(client):
# Initialize appropriate service.
media_service = client.GetService('MediaService', version=API_VERSION)
# Create HTML5 media.
base64_encoded_html5_zip = GetBase64EncodedHTML5ZipFromUrl(
'https://goo.gl/9Y7qI2')
# Create a media bundle containing the zip file with all the HTML5 components.
media = [{
'xsi_type': 'MediaBundle',
'data': base64_encoded_html5_zip,
'type': 'MEDIA_BUNDLE'
}]
# Upload HTML5 zip.
response = media_service.upload(media)

if response:
for media in response:
print(
'HTML5 media with ID %d, dimensions %dx%d, and MIME type "%s" '
'uploaded successfully.' %
(media['mediaId'], media['dimensions'][0]['value']['width'],
media['dimensions'][0]['value']['height'], media['mimeType']))


def GetBase64EncodedHTML5ZipFromUrl(url):
"""Retrieve zip file from the given URL."""
response = urllib.request.urlopen(url)
# Note: The utf-8 decode is for 2to3 Python 3 compatibility.
return base64.b64encode(response.read()).decode('utf-8')


if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage(path=PATH_ADWORDS_CREDENTIALS)
main(adwords_client)


Thank you,

Peter Okunev

unread,
Feb 14, 2018, 8:33:54 AM2/14/18
to AdWords API Forum
Solved:

a) hint from Michael to check the creative here https://h5validator.appspot.com/adwords/asset
b) the error I had is due to response = urllib.request.urlopen(url)
url with redirects like https://goo.gl/9Y7qI2 does not catch the final file

Anash P. Oommen (AdWords API Team)

unread,
Feb 14, 2018, 4:20:20 PM2/14/18
to AdWords API Forum
Hi Peter,

It is still possible that this will fail, due to this: https://greensock.com/forums/topic/17508-google-will-no-longer-support-html5-ads-with-clickability/. The file pointed to by our guide uses ExitApi.js.

Cheers
Anash P. Oommen,
AdWords API Advisor.
Reply all
Reply to author
Forward
0 new messages