AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题

问题[python](computer)

Martin Hope
Twineee The Pickle Wizard
Asked: 2025-04-18 00:19:05 +0800 CST

VSCode Web Python 错误

  • 7

我尝试使用vscode.dev编辑一些文件,但今天打开它时,输出中出现了这些错误。我只在这里编辑过一次 Python 文件,所以我怀疑是不是因为这个,而且我也不明白为什么它会运行它。我该如何解决这个问题?

[CONFIG] ignoring python because it is SUPPRESSED by any of [ms-python.python]
[CONFIG] ignoring typescript because it is SUPPRESSED by any of [vscode.typescript-language-features]
[Error - 11:14:16 AM] Client anycode: connection to server is erroring. Shutting down server.
[Error - 11:14:16 AM] Client anycode: connection to server is erroring. Shutting down server.
python
  • 1 个回答
  • 30 Views
Martin Hope
user1917289
Asked: 2025-02-08 07:50:16 +0800 CST

Wireshark 仅解码一个方向

  • 5
该问题已从 Stack Overflow 迁移,因为它可以在 Super User 上得到解答。4天前迁移 。

我编写了一个使用 TLS 加密的 Python 聊天客户端。服务器在一台 PC 上运行,客户端在另一台 PC 上运行。

服务器创建 SSL 密钥(server.key 和 server.crt),然后我将 server.crt 复制到客户端 PC。

客户端不会创建自己的任何 SSL 密钥。

使用 LD_PRELOAD,我在服务器 PC 上收集 SSLKEYLOGFILE。我也使用服务器 PC 上的 tcpdump 收集 pcap。

我将这两者都带到 Wireshark 来解密 pcap。

但是,只有客户端 -> 服务器数据包被解码。服务器 -> 客户端消息仍保持加密状态。这是为什么呢?

键盘记录.txt:

SERVER_HANDSHAKE_TRAFFIC_SECRET 6e1c671e89c253c9670297d7af1c651236cb52ffcec31f393ff2d4c345b65b83 83156d3d139ab2bda9fb30bc68699fadeaff736373585e9296618973b804e67b858f904b6d67d35791f154d2df1c53ec
CLIENT_HANDSHAKE_TRAFFIC_SECRET 6e1c671e89c253c9670297d7af1c651236cb52ffcec31f393ff2d4c345b65b83 d27b9286b3f209da0cfca1055cd6c5a0b7dc638a3b47b760fc52c46530c6f0129e3ab8cb97de02d708dcd78e4b8eeef6
EXPORTER_SECRET 6e1c671e89c253c9670297d7af1c651236cb52ffcec31f393ff2d4c345b65b83 a81094854b39ab0a39ab4b1d0669591024a3c05d4a8b0df0870e2df824b447b9cdd206e4f120dbeb871a0f642bff783b
SERVER_TRAFFIC_SECRET_0 6e1c671e89c253c9670297d7af1c651236cb52ffcec31f393ff2d4c345b65b83 fa8a418607881a3c78082009acded37a4f1640b6d7e4932785b071bd3dcae67aaef91ef664bb1fc1f01e22d800b11e73
CLIENT_TRAFFIC_SECRET_0 6e1c671e89c253c9670297d7af1c651236cb52ffcec31f393ff2d4c345b65b83 f90a697b55859c7144ccf34c499869cddbec964f37386ab08cf7ed137cd54c53b9c119b42fda4f37b0ba3e5a62694cf7

服务器.py:

import socket
import ssl
import argparse

# Server-side
def create_tls_server(certfile, keyfile, port):
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
    context.load_cert_chain(certfile, keyfile)

    hostname = socket.gethostname()
    IPAddr = socket.gethostbyname(hostname)
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    sock.bind((IPAddr, port))
    sock.listen(2)

    print(f"Server started on {IPAddr}:{port}. Waiting for connections...")

    while True:
        client_socket, addr = sock.accept()  # Accept raw connection
        try:
            ssl_conn = context.wrap_socket(client_socket, server_side=True)  # Wrap here
            print(f"Connected by {addr}. Waiting for message...")
            while True:
                data = ssl_conn.recv(1024).decode()
                if not data:
                    break
                print(f"Received: {data}")
                if data == 'bye':
                    break
                print(">> ", end='')
                response = input()
                ssl_conn.send(response.encode())
        except Exception as e:
            print(f"Error: {e}")
        finally:
            ssl_conn.close()
            client_socket.close()  # close the connection
            print(f"Connection with {addr} closed.")
            break

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="TLS Server")
    parser.add_argument("-p", "--port", type=int, default=8500, help="Port number")
    parser.add_argument("-v", "--version", type=int, default=ssl.PROTOCOL_TLS_SERVER, help="TLS Version")
    args = parser.parse_args()

    create_tls_server('./server.crt', './server.key', args.port)

客户端.py:

import socket
import ssl
import argparse

# Client-side
def connect_tls_client(cafile, port, host):
    context = ssl.create_default_context()
    context.load_verify_locations(cafile)

    sock = socket.socket()  # instantiate
    sock.connect((host, port))  # connect to the server

    client_socket = context.wrap_socket(sock, server_hostname=host)

    print(">> ", end='')
    message = input()

    while message.lower().strip() != 'bye':
        client_socket.send(message.encode())  # send message
        data = client_socket.recv(1024).decode()  # receive response
        if not data:
            break

        print('Received from server: ' + data)  # show in terminal

        if data == 'bye':
            break

        print(">> ", end='')
        message = input()

    client_socket.close()  # close the connection

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="TLS Client")
    parser.add_argument("-s", "--server_ip", default="name-of-remote-serverenter image description here", help="Server IP address")
    parser.add_argument("-p", "--port", type=int, default=8500, help="Port number")
    parser.add_argument("-v", "--version", type=int, default=ssl.PROTOCOL_TLS_SERVER, help="TLS Version")
    args = parser.parse_args()

    connect_tls_client('./server.crt', args.port, args.server_ip)

python
  • 1 个回答
  • 25 Views
Martin Hope
user1785730
Asked: 2023-12-19 12:08:18 +0800 CST

如何运行通过 pip 安装的应用程序?

  • 5

我之前使用过 pip 安装库以在我的 python 脚本中使用它们。现在我已经从 pip 安装了 ranger-fm。

愚蠢的问题:我该如何运行它?

我没想到只需在命令行输入“ranger”即可运行它。我确实尝试过

python3 -m ranger

这给出了这个错误:

/Library/Developer/CommandLineTools/usr/bin/python3: No module named ranger.__main__; 'ranger' is a package and cannot be directly executed
python
  • 1 个回答
  • 67 Views
Martin Hope
Shakir
Asked: 2023-11-21 02:45:28 +0800 CST

用于在 LibreOffice Calc 中的选定行下保持 3 行可见的宏

  • 5

在 Calc 或 MS Excel 中,当编辑完一行中的单元格后,按 Enter 键将转到下面的下一行。继续这样做,最终您将到达屏幕上可见的最后一行。在这里,当您按 Enter 时,它将进入下一行,但现在是最后一行。像 Nreal Air 眼镜一样,很难在屏幕上看到最后一行(因为底部总是模糊的)。我的解决方案是将当前选定的行保留在中间。这意味着每当按下 Enter 时,宏都会检查新选定的行下有多少行可见。如果小于 3,可见行将向上移动(因此将所选行保持在中间)。下列_答案在 MS Excel 中解决了这个确切的问题。我想在 LibreOffice Calc 中做同样的事情。但是,到目前为止,我一直没有成功编写一个宏来检查所选行下的可见行,并在每次按 Enter 时添加一个新行(因此将下一个所选行保留在屏幕中间)。知道如何在 Calc 中做到这一点吗?

python
  • 1 个回答
  • 26 Views
Martin Hope
yen
Asked: 2023-10-04 03:27:59 +0800 CST

所有目录中 bash 终端提示符上的 (venv) 前缀

  • 5

最初,我很高兴看到我的终端提示符带有前缀,(venv)因为我位于正在学习 python 的文件夹内,并且在该文件夹中,我创建了一个./venv文件夹来保存我的虚拟环境,我似乎能够激活该虚拟环境。

今天,我惊讶地发现它现在(venv)在我的机器上的任何其他地方都为我的提示符添加了前缀。

问题

  1. 这是您创建虚拟环境时的标准/预期行为吗?为什么?这些其他文件夹甚至不是 python 项目。
  2. 如何停止疯狂/将 python-env 意识限制为仅相关目录?

echo $PS1给出:

(venv) \u@\h \[\]\w\[\] \[\]$git_branch\[\]$git_dirty\[\]$

并grep -i PS1 ~/.*.rc* ~/.*bash* ~/.profile给出:

/home/me/.bashrc:    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
/home/me/.bashrc:    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
/home/me/.bashrc:    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
/home/me/.bashrc:export PS1="\u@\h \[$txtgrn\]\w\[$txtrst\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "

我也不记得编辑过任何文件,例如 bash_profile .bashrc .profile 等。

谢谢!

更新

我不知道它是否有帮助,但它碰巧检查了我的历史记录以查找与 venv 相关的任何内容:

 1034  python3 -m venv venv
 1035  python3 -m venv ./venv
 1037  rm -rf venv/
 1040  python3 -m venv ./venv
 1042  ll venv/
 1043  ll venv/bin/
 1044  rm -rf venv
 1045  python3 -m venv --without-pip ./venv
 1046  ll venv/bin/
 1047  source ./venv/bin/activate
 1085  history grep "venv"
 1086  history | grep "venv"

这些命令有错误吗?

python
  • 1 个回答
  • 31 Views
Martin Hope
Darren Oakey
Asked: 2023-09-07 09:42:59 +0800 CST

如何从 Windows cmd 运行 python?

  • 6
赏金将在 3 天后到期。此问题的答案有资格获得+50声誉奖励。 Darren Oakey希望引起更多关注这个问题:
我仍然想知道如何做到这一点
这个问题是从 Stack Overflow 迁移过来的,因为它可以在超级用户上得到回答。7 天前迁移 。

我在路径中的脚本目录中制作了很多python 脚本 - 例如 blah.py。我只想输入“blah”来执行 blah.py。

但是当我这样做时 - 文件在 Visual Studio Code 中打开?!

我不明白为什么 - 当我打字时

> ftype | grep -i python
Python.ArchiveFile="C:\WINDOWS\py.exe" "%L" %*
Python.CompiledFile="C:\WINDOWS\py.exe" "%L" %*
Python.File="C:\WINDOWS\py.exe" "%L" %*
Python.NoConArchiveFile="C:\WINDOWS\pyw.exe" "%L" %*
Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*

进而

> assoc | grep -i .py
.py=Python.File
.pyc=Python.CompiledFile
.pyd=Python.Extension
.pyo=Python.CompiledFile
.pyw=Python.NoConFile
.pyz=Python.ArchiveFile
.pyzw=Python.NoConArchiveFile

所以根据我的阅读,.py 应该是一个 Python.File,它应该运行 C:\windows\py.exe。

有任何想法吗?到目前为止,我必须制作一个与每个 .py 文件相对应的 .bat 文件 - 只运行它:(

python
  • 1 个回答
  • 88 Views
Martin Hope
Peter Long
Asked: 2023-08-02 05:36:20 +0800 CST

使用 Selenium 从 Discogs URL 中抓取数据时出现 NoSuchElementException

  • 5

我尝试使用 Selenium 从 Discogs URL 中提取一些数据,但恐怕我从 Selenium 中选择了错误的正确标签

我从这个网址开始

我尝试在控制台中获取此输出

Artista 1: The Sound Man Featuring Mercy (3) – The Factory
Testo elemento 1: The Factory (Original Mix)    
Testo elemento 2: The Factory (Bass Dub)    
Testo elemento 3: The Factory (Junior's Factory Dub)    
Testo elemento 4: The Factory (Sexapella)   
Testo elemento 5: The Factory (Klubb Kidz Flava Dub)    
Testo elemento 6: The Factory (Klubb Kidz School Dub)   
Testo elemento 7: The Factory (Duke's Massive Blast)

为了废弃这个,我用 Selenium 的 DevTools 看看这个部分,我看到了这个

https://i.imgur.com/Q8Sbdk2.png

但我收到这些错误

C:\Users\Peter\Desktop\script\BLOCCO 1\selenium>python canzonidiscogs.py
Inserisci l'URL di Discogs: https://www.discogs.com/it/master/103917-The-Sound-Man-Featuring-Mercy-The-Factory

DevTools listening on ws://127.0.0.1:59139/devtools/browser/b0724a48-9b6e-401f-8e58-7882ae487739
Artista 1: The Sound Man Featuring Mercy (3) – The Factory
Traceback (most recent call last):
  File "C:\Users\Peter\Desktop\script\BLOCCO 1\selenium\canzonidiscogs.py", line 21, in <module>
    artist = element.find_element(By.CSS_SELECTOR, 'td[class^="title_"]> a').text
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 417, in find_element
    return self._execute(Command.FIND_CHILD_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "C:\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"td[class^="title_"]> a"}
  (Session info: chrome=115.0.5790.110); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
Backtrace:
        GetHandleVerifier [0x0069A813+48355]
        (No symbol) [0x0062C4B1]
        (No symbol) [0x00535358]
        (No symbol) [0x005609A5]
        (No symbol) [0x00560B3B]
        (No symbol) [0x00559AE1]

我使用这段代码来执行提取

from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Chiedi all'utente di inserire l'URL di Discogs
url = input("Inserisci l'URL di Discogs: ")

driver = Chrome()
wait = WebDriverWait(driver, 10)

driver.get(url)

title = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'h1[class^="title_"]'))).text
print(f"Artista 1: {title}")

# Utilizziamo il selettore CSS fornito per selezionare gli elementi della tabella
container = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'div[class^="content_1TFzi"]')))

for i, element in enumerate(container, start=1):
    artist = element.find_element(By.CSS_SELECTOR, 'td[class^="title_"]> a').text
    print(f"Artista {i}: {artist}")

driver.quit()
python
  • 1 个回答
  • 22 Views
Martin Hope
King David
Asked: 2023-07-21 13:08:11 +0800 CST

在 RHEL 8 上工作时没有名为 yum 的模块

  • 9

由于我们的应用程序适用于python2RHEL 8,因此我们需要迁移到 RHEL 8

在 RHEL 8 机器上安装后python2,我们看到以下内容:

rpm -qa | grep python2
python2-pip-9.0.3-19.module+el8.6.0+13001+ad200bd9.noarch
python2-setuptools-wheel-39.0.1-13.module+el8.4.0+9442+27d0e81c.noarch
python2-pip-wheel-9.0.3-19.module+el8.6.0+13001+ad200bd9.noarch
python2-2.7.18-11.module+el8.7.0+15681+7a92afba.x86_64
python2-libs-2.7.18-11.module+el8.7.0+15681+7a92afba.x86_64
python2-setuptools-39.0.1-13.module+el8.4.0+9442+27d0e81c.noarch

但是当我们尝试使用 时import yum,我们会收到有关“没有名为 yum 的模块”的错误,并显示以下输出:

python
Python 2.7.18 (default, Jun 17 2022, 07:56:00)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named yum

yum 安装的 rpm 为:

rpm -qa | grep yum
yum-4.4.2-11.el8.noarch
yum-utils-4.0.18-4.el8.noarch

yum 显示为:

more /usr/bin/yum
#!/usr/bin/python
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   %s

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

""" % (sys.exc_value, sys.version)
    sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
    import yummain
    yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
    print >> sys.stderr, "\n\nExiting on user cancel."
    sys.exit(1)

从pip2列表中我们得到这个输出:

pip2 list
pip (9.0.3)
setuptools (39.0.1)

那么为什么我们会收到有关 的错误 No module named yum?

https://www.getpagespeed.com/solutions/python-scripts-running-on-rocky-linux-8-can-not-import-yum

https://access.redhat.com/solutions/4289441

python
  • 1 个回答
  • 219 Views
Martin Hope
Just Me
Asked: 2023-03-05 20:48:45 +0800 CST

使用扩展名为 .bat 的 CMD(命令提示符)打开 Python .py 文件/代码的多个实例

  • 5

我尝试使用 CMD(命令提示符)打开 Python .py 文件/代码的多个实例。因此,我创建了一个扩展名为 .bat 的文件,每次我想打开多个 .py 文件/代码时都会运行它。

这是 .bat 文件中的代码

@echo off
"e:\Carte\BB\App-one.py" 
"e:\Carte\BB\App-two.py" 
"e:\Carte\BB\App-three.py" 
"e:\Carte\BB\App-four.py" 
"e:\Carte\BB\App-five.py" 

我唯一的问题是,当我第一次点击时,Python 关闭,cmd 只会打开第一个“App-one.py”

因此,我必须运行两次 .bat 文件才能打开所有 Python 文件/代码。

现在,我想一键打开所有 .py 文件,而不是两次。

我怎样才能做到这一点 ?

python
  • 1 个回答
  • 20 Views
Martin Hope
anjanesh
Asked: 2023-02-23 20:36:30 +0800 CST

在 powershell 中启动 python 时覆盖 Windows 存储打开操作 [重复]

  • 6
这个问题在这里已经有了答案:
在 Windows 10(版本 1903)命令提示符下键入“python”可打开 Microsoft 商店 (8 个答案)
3 天前关闭。

C:\Users\my-username\AppData\Local\Programs\Python\Python311\python.exe在我的路径中,但是当我在 powershell 中执行 python 时,它会自动打开 Microsoft Store,无论如何都被管理员阻止了。

如何覆盖显然会启动 Windows 应用商店的默认路径?

最新的 Python 是我手动安装的:

PS D:\> C:\Users\CURRENT_USER\AppData\Local\Programs\Python\Python311\python.exe
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
python
  • 1 个回答
  • 21 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve