使用cookies访问经过身份验证的网页时,遇到SSL错误。这似乎是一个特定于mac的问题,很多人通过安装python证书来解决这个问题(正如我在下面的终端会话中所尝试的),但是当我尝试安装时,会抛出一个异常(Permission Denied)。在
我应该如何修复这个错误?在
代码:...
import urllib.request
opener = urllib.request.build_opener()
print("Cookies: ", headers["Cookie"])
opener.addheaders.append(('Cookie', headers["Cookie"]))
f = opener.open("https://home.nest.com/home/"+url_addtl_data)
print(f)
错误消息:
^{pr2}$
尝试的解决方案:Last login: Sat May 11 03:44:45 on ttys000
Ryan-Cocuzzos-Laptop:~ Ryan$ /Applications/Python\ 3.6/Install\ Certificates.command ; exit;
-- pip install --upgrade certifi
Collecting certifi
Using cached https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl
Installing collected packages: certifi
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2019.3.9.dist-info'
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Traceback (most recent call last):
File "", line 44, in
File "", line 25, in main
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6', '-E', '-s', '-m', 'pip', 'install', '--upgrade', 'certifi']' returned non-zero exit status 2.
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...30 completed.
[Process completed]
编辑5/19
其他终端会话(来自建议的解决方案):Ryan-Cocuzzos-Laptop:~ Ryan$ sudo easy_install pip
Password:
Searching for pip
Best match: pip 19.1.1
Adding pip 19.1.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3.7 script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Using /usr/local/lib/python2.7/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
Ryan-Cocuzzos-Laptop:~ Ryan$ brew install python
Updating Homebrew...
Warning: python 3.7.3 is already installed, it's just not linked
You can use `brew link python` to link this version.
Ryan-Cocuzzos-Laptop:~ Ryan$ brew link python
Linking /usr/local/Cellar/python/3.7.3...
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3'
To force the link and overwrite all conflicting files:
brew link --overwrite python
To list all files that would be deleted:
brew link --overwrite --dry-run python
Ryan-Cocuzzos-Laptop:~ Ryan$ rm '/usr/local/bin/2to3'
Ryan-Cocuzzos-Laptop:~ Ryan$ brew link --overwrite python
Linking /usr/local/Cellar/python/3.7.3... 24 symlinks created
Ryan-Cocuzzos-Laptop:~ Ryan$ python -c "import ssl;print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2r 26 Feb 2019
Ryan-Cocuzzos-Laptop:~ Ryan$
编辑5/21
尝试在项目中包含SSL,但它引发错误。。这似乎是相关的,但是,在检查(如上所示)时,您可以注意到python肯定在使用opensslv.1.0.2r