使用Python访问web资源。JSON问题?

使用Python访问web资源。JSON问题?,python,json,python-3.x,authentication,python-requests,Python,Json,Python 3.x,Authentication,Python Requests,我已经尝试了很多,试图让这个工作 网站上有CSV资源,我想下载并保存这些资源,我可以使用firefox实现这一点,但我想自动化这个过程 比如: headers={ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'} payload = { 'email': username, 'pas

我已经尝试了很多,试图让这个工作

网站上有CSV资源,我想下载并保存这些资源,我可以使用firefox实现这一点,但我想自动化这个过程

比如:

headers={ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}

payload = { 'email': username, 'password': password}

with requests.Session() as s:
  p=s.post('https://isaacphysics.org/api/v2.10.4/api/auth/segue/authenticate', json=payload,headers=headers)
print(p.status_code)
webpage=s.get('https://isaacphysics.org/api/v2.10.4/api/assignments/assign/group/24684/progress/download' ,headers=headers) 
post调用返回状态200,返回一些用户数据,以验证它是否工作并创建必要的cookie,但“get”无法进行身份验证

在firefox中,请求如下所示:

Method: GET
URL: https://isaacphysics.org/api/v2.10.4/api/assignments/assign/group/25090/progress/download
Request Headers:
Host: isaacphysics.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Cookie: JSESSIONID=9g94t7JUNKJUNK3blif6bkx; isaacCookiesAccepted=1; SEGUE_AUTH_COOKIE="{\"currentUserId\":\"47878\",\"token\":\"0\",\"DATE_EXPIRES\":\"Tue May 12 13:41:48 +0000 2020\",\"HMAC\":\"Tr+eAeSQWU9JUNKJUNKJUNKJUNKJUNKJUNK2MQVrBQ=\"}"
Upgrade-Insecure-Requests: 1
在python中
打印(网页.请求.标题)

给出:

{'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*',
 'Connection': 'keep-alive', 
'Cookie': 'JSESSIONID=1jr9h3wJUNKJUNKJUNKrpfzx; SEGUE_AUTH_COOKIE="{currentUserId:47878,token:0,DATE_EXPIRES:Tue May 12 18:08:00 +0000 2020,HMAC:3LlaQTN/JUNKJUNKJUNKJUNKJUNKJUNKQW4mo=}"; isaacCookiesAccepted=1'}

明显的区别似乎在于SEGUE_AUTH_COOKIE,因为一些转义字符已被删除。我尝试过几种方法,如果这是一个问题,我想不出如何解决它。非常感谢您的帮助。

api接受基本身份验证吗?我已经尝试过了,但它似乎不接受。我花了很长时间才让post请求起作用,因为更常见的数据=有效负载不起作用。这再次让我觉得JSON Handelling有些可疑,但我不是专家,所以我可能没有用尽所有的可能性。你应该检查api文档。你发布的链接不存在。有一个git中心,我认为它可能很有用。不幸的是,它的文档记录非常糟糕。我不是一个专家,我是一个有点编程知识的物理老师。我想我无法从git-hub中解决这个问题。让我看看