title: urllib.error.HTTPError: HTTP Error 400: Bad Request from trying to get a set of images
body: <p>I was trying to get a set of images for a dataset to train tiny-yolo on so I followed this tutorial </p>
  
  <p><a href="https://www.youtube.com/watch?v=Lg4T9iJkwhE&amp;index=5&amp;list=PLX-LrBk6h3wSGvuTnxB2Kj358XfctL4BM" rel="nofollow noreferrer">https://www.youtube.com/watch?v=Lg4T9iJkwhE&amp;index=5&amp;list=PLX-LrBk6h3wSGvuTnxB2Kj358XfctL4BM</a></p>
  
  <p>The first file that was written in the tutorial goes like this:</p>
  
  <pre><code>import os
  import urllib.request as ulib
  from bs4 import BeautifulSoup as Soup
  import json
  
  url_a = 'https://www.google.com/search?ei=1m7NWePfFYaGmQG51q7IBg&amp;hl=en&amp;q={}'
  url_b = '\&amp;tbm=isch&amp;ved=0ahUKEwjjovnD7sjWAhUGQyYKHTmrC2kQuT0I7gEoAQ&amp;start={}'
  url_c = '\&amp;yv=2&amp;vet=10ahUKEwjjovnD7sjWAhUGQyYKHTmrC2kQuT0I7gEoAQ.1m7NWePfFYaGmQG51q7IBg'
  url_d = '\.i&amp;ijn=1&amp;asearch=ichunk&amp;async=_id:rg_s,_pms:s'
  url_base = ''.join((url_a, url_b, url_c, url_d))
  
  headers = {'User-Agent': 'Chrome/67.0.3396.99 Safari/537.36'}
  
  
  def get_links(search_name):
      search_name = search_name.replace(' ', '+')
      url = url_base.format(search_name, 0)
      request = ulib.Request(url, None, headers)
      json_string = ulib.urlopen(request).read()
      page = json.loads(json_string)
      new_soup = Soup(page[1][1], 'lxml')
      images = new_soup.find_all('img')
      links = [image['src'] for image in images]
      return links
  
  
  def save_images(links, search_name):
      directory = search_name.replace(' ', '_')
      if not os.path.isdir(directory):
          os.mkdir(directory)
  
      for i, link in enumerate(links):
          savepath = os.path.join(directory, '{:06}.png'.format(i))
          ulib.urlretrieve(link, savepath)
  
  
  if __name__ == '__main__':
      search_name = 'my search query'
      links = get_links(search_name)
      save_images(links, search_name)
  </code></pre>
  
  <p>The only thing I changed was the headers variable since my User-agent is different than the guy in the tutorial's one. </p>
  
  <p>To my supprise the script returned this error </p>
  
  <pre><code>urllib.error.HTTPError: HTTP Error 400: Bad Request
  </code></pre>
  
  <p>Can anyone tell me what's wrong? </p>