Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:32:07+00:00 2026-06-06T01:32:07+00:00

I am trying to write a function that will allow me to browse for

  • 0

I am trying to write a function that will allow me to browse for a CSV file, and then parse that CSV file, before sending off each value to the Google Search API (that bit is already written).

So right now I’ve got this:

def loadtemplate():
    filename = tkFileDialog.askopenfilename(filetypes = (("CSV files", "*.csv")
                                                             ,("Text Files", "*.txt")
                                                             ,("All files", "*.*") ))
    if filename: 
            try: 
                csvfile = csv.reader(open(filename, 'rb'), delimiter=',')
                for row in csvfile:
                    for x in row:
                            generate(x)
            except: 
                tkMessageBox.showerror("Open Source File", "Failed to read file \n'%s'"%filename)
                return

And my CSV file looks like this:

seo,company name,drupal,wordpress themes,awesome web design

Nothing too crazy. Anyway, I’m getting this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:/Python27/Projects/Google Searcher/realsearcher.py", line 20, in loadtemplate
    generate(x)
  File "C:/Python27/Projects/Google Searcher/realsearcher.py", line 31, in generate
    gs = gs['cursor']
TypeError: 'NoneType' object is not subscriptable

It seems like somehow a value is being set to None? But I keep either trying to use a conditional where if x == None:, it’ll not allow the query to go through or try to change the CSV file to where nothing like that should be parsed.

What’s going on here, and how do I fix it?

PS – this is what the variable row looks like:

['seo', 'company name', 'drupal', 'wordpress themes', 'awesome web design']

Here is generate() (I used duplicate code because I felt that writing something that would do both solutions would take longer and was unnecessary because this project won’t be expanded):

def generate(item):
    infoget = urllib.quote(item)
    infoquote = '"' + infoget + '"' 
    response = urllib2.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + infoget)
    gs = simplejson.load(response)
    gs = gs['responseData']
    gs = gs['cursor']
    gs = gs['estimatedResultCount']
    print gs
    response = urllib2.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + infoquote)
    gs = simplejson.load(response)
    gs = gs['responseData']
    gs = gs['cursor']
    gs = gs['estimatedResultCount']
    print gs
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:32:08+00:00Added an answer on June 6, 2026 at 1:32 am

    It should be obvious from the traceback that the problem has nothing whatsoever to do with the CSV loading, but comes from the generate function. We can see from the code for that function that you’re querying the Google Search API (for every item in every line!). However, in various cases, you’re getting a blank result back.

    You should rewrite the generate function to be a little more sensible, without spamming Google (they don’t like it), and dealing with failures a sensibly – checking that the nested values exist in the JSON before relying on them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that will trim all the letters off
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates
I'm trying to write a function that will return all the available cars for
I am trying to write a function that will convert a generic list to
I'm trying to write a short function that will let me quickly read in
I'm trying to write a regular expression (via Autohotkey's RegExReplace function) that will enforce

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.