python自.strftime(“%S”)类型错误:无法将字节合并到%S

2024-04-20 11:27:51 发布

您现在位置:Python中文网/ 问答频道 /正文

使用pycharm编写程序(python 3.6),部分程序如下:

DAYS = 14 #nO need to modify this
GRAPH_URL_PREFIX = "https://graph.facebook.com/"
GROUP_SUFFIX = "/groups"      
DEFAULT_LIMIT = "100"        #Set to true if you like seeing console output
VERBOSE = True               #Calculating a timestamp from DAYS
SINCE = datetime.datetime.now() - datetime.timedelta(DAYS)


def getFeed(access_token,group,name):

    #Token-based auth header
    headers = {"Authorization":"Bearer " + access_token}


    params = "?fields=permalink_url,from,story,type,message,link,created_time,updated_time,likes.limit(0).summary(total_count),comments.limit(0).summary(total_count)"

    #Default paging limit
    params += "&amp&limit=" + DEFAULT_LIMIT

    #Time-based limit

    params += "&since=".encode("utf-8") + str(SINCE.strftime("%S"))

    graph_url = GRAPH_URL_PREFIX + group + "/feed" + params
    ...

it错误:

    File "C:\Python\PyCharmProject\FaceBookCrawl\group_download.py", line 32, in getFeed
    params = params.encode("utf-8") + str(SINCE.strftime("%S"))
    TypeError: can't concat bytes to str

但是我已经将params和SINCE.strftime("%S")设置为str,为什么


Tags: todefaulturldatetimeprefixgroupparamsdays