简体   繁体   中英

Python3 urllib.error.URLError: <urlopen error [Errno 110] Connection timed out> on server

I have script which have to build an new.xml file from.xml file on some URL, when I run script on my PC, everything is okay.But after I try to run on my server, it throws urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>

I don't know why and I didn't find any good source where this problem was described, so I want this script running on my server automatically as CRON, but I can't.. Does not works..

Code:

#!/usr/bin/env python3
import urllib.request, urllib.parse, urllib.error
import xml.etree.ElementTree as ET 
  
url = 'http://eshop.cobi.cz/modules/xmlfeeds/xml_files/feed_5.xml'
uh = urllib.request.urlopen(url, timeout=30)
  
tree = ET.parse(uh)

root = tree.getroot() 


data = ET.Element('SHOP')   

for r in root.findall('SHOPITEM'):
    name = r.find('PRODUCT').text
    try:
      description = r.find('DESCRIPTION').text
    except AttributeError:
      description = ""
      continue
    price = r.find('WHOLESALEPRICE').text
    new_price = (float(price) * 0.8)  
    final_price = round(new_price, 2)
    final_price = str(final_price)
    ean = r.find('EAN').text
    sku = r.find('PRODUCTNO').text
    for i in r.findall('IMAGES'):
      img = i.find('IMGURL').text
    status = r.find('ACTIVE').text
    if status == '1':
        status = '1'
    else: 
        status = '0'
        continue
    
    element2 = ET.SubElement(data, 'SHOPITEM') 
    
    s_elem2_1 = ET.SubElement(element2, 'PRODUCTNAME')
    s_elem2_2 = ET.SubElement(element2, 'PRODUCT')
    s_elem2_3 = ET.SubElement(element2, 'DESCRIPTION')
    s_elem2_4 = ET.SubElement(element2, 'PRICE_VAT')
    s_elem2_5 = ET.SubElement(element2, 'EAN')
    s_elem2_6 = ET.SubElement(element2, 'PRODUCTNO')
    s_elem2_7 = ET.SubElement(element2, 'IMGURL')
    s_elem2_8 = ET.SubElement(element2, 'DELIVERY_DATE')
    s_elem2_9 = ET.SubElement(element2, 'CATEGORYTEXT')
    s_elem2_10 = ET.SubElement(element2, 'MANUFACTURER')
    s_elem2_11 = ET.SubElement(element2, 'ACTIVE')
    
    s_elem2_1.text = "Cobi " + name
    s_elem2_2.text = "Cobi " + name
    s_elem2_3.text = description
    s_elem2_4.text = final_price
    s_elem2_5.text = ean
    s_elem2_6.text = sku 
    s_elem2_7.text = img
    s_elem2_8.text = "7"
    s_elem2_9.text = "Heureka.cz | Dětské zboží | Hračky | Stavebnice | Stavebnice Cobi"
    s_elem2_10.text = "Cobi"
    s_elem2_11.text = status
    
    xml_content = ET.tostring(data)

    with open('cobifeed.xml', 'wb') as f:
        f.write(xml_content)
        f.close()

try ping shop.cobi.cz from cmd/bash and wget http://eshop.cobi.cz/modules/xmlfeeds/xml_files/feed_5.xml

Probably You dont have network access to server eshop.cobi.cz

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM