urllib urlopen [WinError 10061]

时间:2018-05-22 22:34:23

标签: python-3.x urllib

遇到以下错误: [WinError 10061]无法建立连接,因为目标计算机主动拒绝它。     确认服务已经开始,服务方面没有问题。 如果我直接运行如下代码,则不会出现错误:

Class Test(testContainer):
    restcall = "http://localhost:8086/service/records/all"
    def__int__(self):
        #service is started in init, 
     ...
     def restCallTest(self):
         getRecordsUrl = "http://localhost:8086/service/records/all"
         try:
            allRecordsResponse = urlopen(getRecordsUrl)
         except URLError as e:
             print(e.reason)
         return allRecordsResponse

      def test(self):
          response = urlopen(self.restCall)

但如果我通过在Test中调用restCallTest来运行如下,则会有WinError 10061

Class Test(testContainer):
    restcall = "http://localhost:8086/service/records/all"
    def__int__(self):
        #service is started in init, 
     ...
     def restCallTest(self):
         getRecordsUrl = "http://localhost:8086/service/records/all"
         try:
            allRecordsResponse = urlopen(getRecordsUrl)
         except URLError as e:
             print(e.reason)
         return allRecordsResponse

      def test(self):
          response = self.restCallTest()

0 个答案:

没有答案