大家好!
我正在尝试从python中的API请求:
headers = {"Content-Type": "application/json", "user-key": self.api_key}
params = {self.filter_fields: '*', self.filter_date: self.date_millis, self.limit: '2'}
request = requests.get(self.api_endpoint, headers=headers, params=params)
我仔细检查过,看看我的过滤器和api键都没问题。问题是,当我打印请求内容“print(request.json())”时,我得到以下错误:
{'Err': {'status': 400, 'message': "Invalid content encoding please change 'Content-Type' header."}}
答案 0 :(得分:1)
代码执行GET请求。它指定内容类型是JSON,但是,请求正文中没有传递JSON内容。
尝试省略内容类型标题。
另一种可能性是使用int selection;
while (true) {
selection = printing();
if (selection == 4) {
id = starting();
if (id < 1 || id > 10) {
if (id == -20150901) {
System.out.println("Exit code entered");
break;
}
id = incorrectId(id);
}
}
}
public static int printing(){
Scanner sc = new Scanner(System.in);
System.out.print("Main menu\n1: check balance\n2: withdraw\n3: deposit\n4: exit\nEnter a choice: ");
System.out.print("Enter a choice: ");
int selection = sc.nextInt();
return selection;
}
参数传递参数。内容类型不需要在标题中设置,json
会自动发送:
requests