排查类型错误

Troubleshoot the TypeError

我想搜索 google 用户请求的药物。代码如下:

import requests
import bs4 as st
from googlesearch import *
from tkinter import *


def funca(base):
    base.withdraw()

    def find():
        ml = ['Syrup', 'Tablet', 'Capsule', 'Lotion', 'Non-swallowed tablets', 'Drops', 'Injection', 'Implant',
              'Others']
        with open('medvar.txt') as m:
            me = m.read()
        mn = meed.get()
        query = me,ml[mn]

        for i in search(query,tld='com.in',num=15,pause=3):
            print(i)


    def bake():
        base.deiconify()
        alu.withdraw()

    meed = IntVar()

    alu = Toplevel(bg='Green')
    alu.geometry('750x500')
    a = Radiobutton(alu, text='Syrup', value=0, variable=meed)
    a.place(x=200, y=0)
    ab = Radiobutton(alu, text='Tablet', value=1, variable=meed)
    ab.place(x=200, y=40)
    b = Radiobutton(alu, text='Capsule', value=2, variable=meed)
    b.place(x=200, y=80)
    c = Radiobutton(alu, text='Lotion', value=3, variable=meed)
    c.place(x=200, y=120)
    d = Radiobutton(alu, text='Non-swallowed tablets', value=4, variable=meed)
    d.place(x=200, y=160)
    de = Radiobutton(alu, text='Drops', value=5, variable=meed)
    de.place(x=200, y=200)
    e = Radiobutton(alu, text='Injection', value=6, variable=meed)
    e.place(x=200, y=240)
    f = Radiobutton(alu, text='Implant', value=7, variable=meed)
    f.place(x=200, y=280)
    g = Radiobutton(alu, text='Others', value=8, variable=meed)
    g.place(x=200, y=320)
    Get = Button(alu, text='Get', font=('Cooper Black', 25), command=find)
    Get.place(x=210, y=415)
    bet = Button(alu, text='Back', command=bake)
    bet.pack(anchor='sw')

但问题是它会抛出以下错误。我已尝试在网上找到的所有方法,但问题并未解决。

Traceback (most recent call last):
  File "D:\assets\New folder (2)\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "D:\Python divane\Healthifyapp\Main app\Main page\knfsub.py", line 18, in find
    for i in search(query,tld='com.in',num=15,pause=3):
  File "D:\Python divane\Healthifyapp\lib\site-packages\googlesearch\__init__.py", line 254, in search
    query = quote_plus(query)
  File "D:\assets\New folder (2)\lib\urllib\parse.py", line 886, in quote_plus
    string = quote(string, safe + space, encoding, errors)
  File "D:\assets\New folder (2)\lib\urllib\parse.py", line 870, in quote
    return quote_from_bytes(string, safe)
  File "D:\assets\New folder (2)\lib\urllib\parse.py", line 895, in quote_from_bytes
    raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes

非常感谢您的帮助,因为我正在进行这个庞大的项目

我认为你正在使用 this function:

googlesearch.search(str: term, int: num_results=10, str: lang="en") -> list

所以第一个参数必须是字符串。但是,您的代码是这样做的:

query = me,ml[mn]

这将创建一个包含两个字符串的元组。我认为您想连接两个字符串:

query = me + ml[mn]