What is the best way to handle the error "Attribute provided with no value: url"

3,033 views
Skip to first unread message

DG

unread,
Jan 15, 2015, 11:49:12 AM1/15/15
to adwords...@googlegroups.com
Basically  it's an in stock/ out of stock script and sometimes I get thrown this error that stops the script before it can complete.

I was wondering what's the best way to work around this? I've tried:
var dest_url = ad_iter.next().getDestinationUrl();
var
html = UrlFetchApp.fetch(dest_url, {}).getContentText();

if(html == null) {
      Logger.log("No URL detected");
    }

  But given the fact the error is continuing that is not correct.

Any help would be greatly appreciated.
Thanks,
DG

Alexander Wang

unread,
Jan 15, 2015, 3:34:05 PM1/15/15
to adwords...@googlegroups.com
Hi DG,
I think usually that error implies that you are calling UrlFetchApp with an empty string. UrlFetchApp is throwing the exception (not just logging it), which will cause the script to stop. It would be easier to diagnose if you used try-catch when calling UrlFetchApp.fetch:
var dest_url = ad_iter.next().getDestinationUrl();
var html;
try {
  html
= UrlFetchApp.fetch(dest_url, {}).getContentText();
} catch (e) {
 
Logger.log("Could not fetch html for " + dest_url + ": " + e);
}
if (html == null) {
 
Logger.log("Could not fetch html");
}

The above code will "catch" this error and will allow your script to continue executing (and hopefully make it easier to diagnose the issue). Without seeing the rest of your script (and assuming the issue is that "dest_url" is empty), I don't know why dest_url would be empty/malformed. Maybe there's a type of ad in your account that doesn't have a destination url? If it's not clear why this is happening, you can send a private reply with your account id and the name of the script and we can take a closer look.

Cheers,
Alex

DG

unread,
Jan 19, 2015, 6:18:29 AM1/19/15
to adwords...@googlegroups.com
I've sent a private reply.

Alexander Wang

unread,
Jan 22, 2015, 5:52:49 PM1/22/15
to adwords...@googlegroups.com
Responded privately, but I also want to give a general response in case anyone else runs into similar issues.

It does in fact appear that the problem was UrlFetchApp.fetch() was being called with an empty string. In this case, the code is assuming all ads have a destination url, which is not the case (certain ad types do not have destination urls). This can be addressed by either filtering out ads that don't have a destination url:
var ad_iter = AdWordsApp.ads().withCondition("DestinationUrl CONTAINS 'h'").get();

Or by skipping ads that don't have a destination url:
var dest_url = ad_iter.next().getDestinationUrl();
// Only fetch pages if the dest_url is not null.
if (dest_url) {
 
var html = UrlFetchApp.fetch(dest_url, {}).getContentText());
 
// do stuff with the html.
 
...
}

Cheers,
Alex
Reply all
Reply to author
Forward
0 new messages