使用以下代码。其中遍历消息ID列表并创建http请求,然后附加到json。我遇到异常问题。尝试除了Else似乎没有用。
int[] array1=new int[10];
int[] array2=new int[10];
int[] array3=new int[10];
// populate array1 and array2 ....
boolean isInArray2;
int current;
int counter = 0;
for (int i = 0; i < array1.length; i++) {
current = array1[i];
isInArray2= false;
for (int j = 0; j < array2.length; j++) {
if(array2[j] == current) {
isInArray2= true;
break;
}
}
if(!isInArray2) {
// not in array2 -> must add in array3
array3[counter] = current;
counter++;
}
}
// Trim array3 to avoid null values:
int[] tmp = array3;
array3=new int[counter];
for (int i = 0; i < array3.length; i++) {
array3[i] =tmp[i];
}
我真的希望它跳过错误并继续下一次迭代。
但是我经常在随机的迭代次数中抛出这个:
import urllib3
import json
import csv
from progressbar import ProgressBar
import time
pbar = ProgressBar()
base_url = 'https://api.pipedrive.com/v1/mailbox/mailMessages/'
fields = {"include_body": "1", "api_token": "token"}
json_arr = []
http = urllib3.PoolManager()
with open('msgid.csv', newline='') as csvfile:
for x in pbar(csv.reader(csvfile, delimiter=' ', quotechar='|')):
while True:
try:
r = http.request('GET', base_url + "".join(x), fields=fields)
break
except Exception:
time.sleep(1)
mails = json.loads(r.data.decode('utf-8'))
json_arr.append(mails)
with open('JDATA.json', 'w', encoding="utf-8") as outfile:
json.dump(json_arr, outfile)