certificate verify failed: unable to get local issuer certificate
报错信息如下:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007) ... urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)>
# pip install --upgrade pip Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (23.0.1) Collecting pip Downloading pip-23.2.1-py3-none-any.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/2.1 MB ? eta -:--:--ERROR: Exception: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper status = run_func(*args) File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper return func(self, options, args) ... File "/usr/local/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 107, in get_http_url from_path, content_type = download(link, temp_dir.path) File "/usr/local/lib/python3.9/site-packages/pip/_internal/network/download.py", line 147, in __call__ for chunk in chunks: File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/progress_bars.py", line 52, in _rich_progress_bar with progress: File "/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/progress.py", line 1169, in __enter__ self.start() File "/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/progress.py", line 1160, in start self.live.start(refresh=True) File "/usr/local/lib/python3.9/site-packages/pip/_vendor/rich/live.py", line 132, in start self._refresh_thread.start() File "/usr/local/lib/python3.9/threading.py", line 899, in start _start_new_thread(self._bootstrap, ()) RuntimeError: can't start new thread
[notice] A new release of pip is available: 23.0.1 -> 23.2.1 [notice] To update, run: pip install --upgrade pip
>>> help(requests.get) get(url, params=None, **kwargs) Sends a GET request. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary, list of tuples orbytes to send in the query string for the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :return: :class:`Response <Response>` object :rtype: requests.Response
def read_large_file(file_path): """ Generator function to read a large file line by line. """ with open(file_path, 'r') as file: for line in file: yield line
使用以下方法使用大文本中的数据
next 方法。调用生成器函数(read_large_file),会返回一个 Generator 对象,通过 next() 方法会迭代调用生成器的下一个值(yield 表达式的值)
file_path = 'large_file.txt' # next 方法: 首先 line = read_large_file(file_path)
next(line) # 返回第一行 next(line) # 返回第二行,以此类推可以读取所有行
for 循环。调用生成器函数返回一个生成器对象,这个对象实现了迭代器协议。
def read_large_file(file_path): """ Generator function to read a large file line by line. """ with open(file_path, 'r') as file: for line in file: yield line # Usage example file_path = 'large_file.txt' for line in read_large_file(file_path): print(line.strip())
分批读取大文件中的数据
在处理大文件的过程中,如果需要批量多行读取文件内容,参考以下代码
def read_file_in_chunks(file_path, chunk_size=1024): """ Generator function to read a file in chunks. """ with open(file_path, 'r') as file: while True: chunk = file.readlines(chunk_size) if not chunk: break for line in chunk: yield line # Usage example file_path = 'large_file.txt' for line in read_file_in_chunks(file_path): print(line.strip())
tasks: - name: Install nginx only if nginx_install is true apt: name: nginx state: present when: nginx_install
- name: Install nginx on Debian or Ubuntu apt: name: nginx state: present when: ansible_facts['os_family'] == 'Debian' or ansible_facts['os_family'] == 'Ubuntu'
- name: Ensure package is installed if it is in the list apt: name: "{{ item }}" state: present loop: "{{ packages_to_install }}" when: item in packages_to_install
- name: Run only if the key 'run_task' is present in mydict and its value is true debug: msg: "Running task" when: mydict.get('run_task', False)
--- - name: Change hostname based on inventory alias hosts: test_target1 become: yes tasks: - name: Set hostname from alias hostname: name: "{{ inventory_hostname }}"