我编写了以下python代码,它连接到一个URL以使用json获取数据。但是,当我的服务器记录这些请求时,它们每次都会生成两次。
我认为这与它首先使用resp Sat Jun 06 2015 00:00:00 GMT+0530 (IST)
typeof object
myObj._id 556a12168c9206a6123dd7d1
::=> { _id: 556a12168c9206a6123dd7d1,
name: 'Electronics',
credits: 50,
__v: 0 }
resp Thu Sep 10 2015 00:00:00 GMT+0530 (IST)
typeof object
myObj._id 556abedc195287dc1136f0be
::=> { _id: 556abedc195287dc1136f0be,
name: 'Mechanical',
credits: 60,
__v: 0 }
然后在满足try方法时重新请求URL这一事实有关。有关我如何才能做到这一点的任何建议,以便它只向服务器发送一次请求?感谢
try
答案 0 :(得分:0)
第一次请求:
json_obj = urllib.request.urlopen(remoteURL)
第二次请求:
with urllib.request.urlopen(remoteURL) as response: