小编web*_*rzi的帖子

使用urllib2进行Python身份验证

所以我正在尝试使用python从名为vsearch.cisco.com的站点下载文件

[蟒蛇]

#Connects to the Cisco Server and Downloads files at the URL specified

import urllib2

#Define Useful Variables

url = 'http://vsearch.cisco.com'
username = 'xxxxxxxx'
password = 'xxxxxxxx'
realm = 'CEC'

# Begin Making connection

# Create a Handler -- Also could be where the error lies

handler = urllib2.HTTPDigestAuthHandler()
handler.add_password(realm,url,username,password)

# Create an Opener

opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

try:
    urllib2.urlopen(url)
    print f.read()

except urllib2.HTTPError, e:
    print e.code
    print e.header
Run Code Online (Sandbox Code Playgroud)

[/蟒蛇]

我的错误是ValueError:AbstractDigestAuthHandler不知道基本的

我尝试过使用Basic HTML Authorization处理程序甚至HTTPS处理程序.什么都没有让我访问.但是,此错误与所有其他错误不同.其他错误只是401 HTML错误

有关如何做到这一点的任何建议?

python

4
推荐指数
1
解决办法
5312
查看次数

Shell 脚本搜索和删除非文本文件

我想编写一个shell脚本来搜索和删除目录中的所有非文本文件。

我基本上 cd 进入我想在脚本中迭代的目录并搜索所有文件。

——这是我不能做的部分——

如果文件是文本文件,我想使用 if 语句检查。如果不是,我想删除它,否则继续

谢谢

PS顺便说一下这是在linux中

编辑

我假设一个文件是一个“文本文件”,当且仅当它的名称与 shell 模式匹配时*.txt

scripting

2
推荐指数
1
解决办法
906
查看次数

标签 统计

python ×1

scripting ×1