내가 스크립트를 작성하고 정의 내 스크립트에 이런 기능이있다 : 나는 시도 어획량을 추가 할 때까지기능은
def insert_image(cursor, object_id, sku):
product_obj = core.Object.get(object_id)
string_sku = str(sku)
folder = string_sku[0] + string_sku[1] + string_sku[2]
found_url = False
# KLUDGE This is ugly and redundant, however putting this in an if elif elif else throws error when url not found
# try this url first
try urllib.urlopen("http://<path to images>/%s/%sPR-IT,PM.jpg" % (folder, sku)):
urllib.URLopener().retrieve("http://<path to images>/%s/%sPR-IT,PM.jpg" % (folder, sku), "%sPR-IT,PM.jpg" % (sku))
found_url = True
except:
found_url = False
# If that one didn't work try this one
if found_url == False:
try urllib.urlopen("http://<path to images>/%s/%sPK-PT,PM.jpg" % (folder, sku)):
urllib.URLopener().retrieve("http://<path to images>/%s/%sPK-PT,PM.jpg" % (folder, sku), "%sPK-PT,PM.jpg" % (sku))
found_url = True
except:
found_url = False
# If still nothing, one last attempt
if found_url == False:
try urllib.urlopen("http://<path to images>/%s/%sCC-PT,IM.jpg" % (folder, sku)):
urllib.URLopener().retrieve("http://<path to images>/%s/%sCC-PT,IM.jpg" % (folder, sku), "%sCC-PT,IM.jpg" % (sku))
found_url = True
except:
found_url = False
# We failed to find an image for this product, it will have to be done manually
if found_url == False:
log.info("Could not find the image on notions")
return False
# Hey we found something! Open the image....
send_image = open('%sPK-PT,PM.jpg' % sku, 'r')
# ...and send it for processing
if product_obj.set_image(send_image, 5, 1) == False:
return False
else:
log.debug("Inserted Image")
return True
이 잘했다. 나는 if, elif를 가지고 있었고, 함수는 잘 돌아갔다.
if rollback == False:
# Nah -- it's all good SAVE IT!
count += 1
log.debug("INSERT %s" % count)
conn.commit()
else:
# Yeah something went wrong, errors reported why, roll it back
conn.rollback()
log.debug("skipped %s" % skip_count)
# Insert images
if rollback == False:
sku = row[0]
if insert_image(cursor, object_id, sku) == False:
log.error("Could not get the image inserted for product: %s" % object_id)
conn.rollback()
else:
conn.commit()
내 오류는 다음과 같습니다 : 여기 내 전화 및 바로 전에 실행되는 코드의의 peice는
전화 라인 2101가 뭔지 라인 47 의미하기 때문에 나도 몰라16:33:46,153 DEBUG [pylons-admin] Inserted Description
16:33:46,164 DEBUG [pylons-admin] Inserted Attributes
16:33:46,164 DEBUG [pylons-admin] INSERT 1
Traceback (most recent call last):
File "<console>", line 47, in <module>
NameError: name 'insert_image' is not defined
, trys를 추가하기 전에 다시 함수를 찾았습니다. insert_image를 호출 한 후 커밋이 발생하기 전에 지금 보았던 것처럼 trys를 추가 할 때 insert_image 호출 전에 첫 번째 커밋을 전환했다. 들여 쓰기와 공백, 탭을 확인했습니다.
try urllib.urlopen("http://<path to images>/%s/%sPR-IT,PM.jpg" % (folder, sku)):
그것은 가리키는 (폴더 (에 ... 그러나 나는이 위치를 확인하지 않습니다
내가 TextMate를를 사용하는 내가 TextMate를에서 스크립트를 실행할 때, 내가 여기에 구문 오류가
구문 오류가 발생했습니다. 제발 도와주세요. 나는이 스크립트에 대해 2 주 동안 작업 해왔다. 테스트를 마친 후 마지막으로 테스트를 마쳤다. (
-1 : 와우는 많은 코드입니다. 문제를 보여주기에 충분한 코드로 줄였습니까? –