Python SSL:使用Google-Search-API进行CERTIFICATE_VERIFY_FAILED

时间:2018-06-02 03:37:19

标签: python ssl google-search-api

我在一个小python程序中使用Google Search API。当我有一个简单的功能时:

def find_url(search_term):
    result = google.search(search_term)

如果search_term是一个字符串,我会收到错误:

Error accessing: http://www.google.com/search?nl=en&q=hello&start=0&num=10
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)>

我不确定为什么我会遇到这个错误。我无法找到直接使用此Google Search API的任何stackoverflow帖子,并且在github上没有提及ssl错误。

编辑:这是我的完整代码

import matplotlib
matplotlib.use('TkAgg') #Stops crashing
from tkinter import * 
from bs4 import BeautifulSoup
import requests
import sys
sys.path.append('/Users/Cactus/wiki-word-frequency/Google-Search-API')
from google import google

def find_url(search_term):
    result = google.search(search_term)
    print(result)

if __name__ == "__main__":
    def do():
        graph.main()
    def get_text_button(): #On button click
        find_url(search.get())
    def get_text_enter(search): #On pressing enter/return
        find_url(search.widget.get())

    root =Tk()
    #root.geometry('{}x{}'.format(600, 400))
    #Make layout look good when uncommenting the above line

    title = Label(root, text="Hello tkinter!")
    title.grid(column=0, row=0, columnspan=2)

    label = Label(root, text="Search term: ")
    label.grid(column=0, row=1)

    search = Entry(root, bd=3)
    search.bind("<Return>", get_text_enter)  
    search.grid(column=1, row=1)

    button = Button(root, text="Submit", command=get_text_button)
    button.grid(column=1, row=2, columnspan=1)
    exit = Button(root, text="Exit", command=root.destroy)
    exit.grid(column=0, row=2, columnspan=1)

    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)

    root.mainloop()

1 个答案:

答案 0 :(得分:0)

我不熟悉API,但是我在使用其他库(requests时)时遇到此错误消息,以发出非安全的http请求。请注意,http://www.google.com/search?...http作为前缀,而不是安全和加密的https。无法完全诊断问题,但也许这会让其他人得到答案。