Python invalid syntax on conditional
我这里有这个python代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def location(location_id, max_id=None): # Send http request to find location if (self.login_status): get_location = {'location_id': location_id} url_location_detail = self.url_location_detail % (location_id) try: get_location_id = self.i.get(url_location_detail, data=body) if location.status_code == 200: log_string ="Get location id: %d" % (location_id) self.write_log(log_string) if max_id is not None: payload['max_id'] = max_id try: res = requests.get(url, params=payload).json() body = res['location'] cursor = res['location']['media']['page_info']['end_cursor'] except: raise return InstagramExploreResponse(data=body, cursor=cursor) |
当我运行程序时,它会引发以下错误:
1 | SyntaxError: invalid syntax |
错误似乎出现在第447行,如下所示:
1 | if max_id is not None: payload['max_id'] = max_id |
奇怪的是,代码以前是有效的,我在这行之前添加了一些代码,所以我认为错误来自前一行。
不幸的是,我看不见。
谢谢!
你可以在这里找到你需要的:在一行上放一个简单的if-then语句
他们已经解释了为什么会出现这种错误以及解决它的一些方法
更清楚地说,在python中,不能将EDOCX1中的内容(0)放在EDOCX1中的前面。这是:
1 | if max_id is not None: payload['max_id'] = max_id |
成为这样:
1 2 | if max_id is not None: payload['max_id'] = max_id |