Python Django模型:从ftp服务器下载图像
首先对不起,我的英语不是我的母语。我正在用Python2.7编写一个XML解析器。有一个图像链接,正在下载并保存到数据库中,它可以很好地使用http,但我需要从ftp服务器下载它们。 下面是从解析器调用的函数:Python Django模型:从ftp服务器下载图像,python,xml,django,ftp,Python,Xml,Django,Ftp,首先对不起,我的英语不是我的母语。我正在用Python2.7编写一个XML解析器。有一个图像链接,正在下载并保存到数据库中,它可以很好地使用http,但我需要从ftp服务器下载它们。 下面是从解析器调用的函数: q=sa_web_images.objects.create( web_image_url=iphoto, web_item_id=wi_id, non_repeat=non_repeat ) q.get_remote_image() 其中“iphoto”是一
q=sa_web_images.objects.create(
web_image_url=iphoto,
web_item_id=wi_id,
non_repeat=non_repeat
)
q.get_remote_image()
其中“iphoto”是一个链接,例如:
下面是将其保存到DB中的函数:
def get_remote_image(self):
if self.web_image_url and not self.web_image:
result = urllib.urlretrieve(self.web_image_url)
self.web_image.save(
os.path.basename(self.web_image_url),
File(open(result[0]))
)
self.save()
我知道ftp访问的用户名和密码,但我不知道,我应该如何将它们插入代码中,有人能帮我吗?谢谢。可以通过在url中指定用户名和密码来向urllib提供用户名和密码,例如
result = urllib.urlretrieve("ftp://user:password@example.com/image.jpg")