小编Sup*_*tew的帖子

如何从外部文件读取列表,以便当我输入用户名时,如果该用户名在该外部文件上,则会打印真值?

我输入了一个用户名 - “User1” - 但是结果总是显示“User1”是一个不正确的用户名,即使它在外部文本文件中。

import random

print ("Welcome to the Music Quiz!")

username = input("please enter your Username...")

f = open("F:/GCSE/Computer Science/Programming/username.txt","r");
lines = f.readlines()


if username == "lines":
    print = input("Please enter your password")

else:
    print("That is an incorrect username")
Run Code Online (Sandbox Code Playgroud)

如果用户名 - User1 User2 User3 User4 User5 作为用户名输入,则输出应为“请输入您的密码”

python

5
推荐指数
1
解决办法
109
查看次数

Python 请求从 GET 运行 JS 文件

目标

使用 python requests 等登录此网站(https://www.reliant.com)(我知道这可以使用 selenium 或 PhantomJS 或其他东西来完成,但我不想这样做)

问题

在登录过程中,有几个重定向,其中传递“会话 ID”类型参数。其中大部分我都能得到,但有一个似乎dtPC来自您第一次访问该页面时获得的 cookie。据我所知,cookie源自这个JS文件(https://www.reliant.com/ruxitagentjs_ICA2QSVfhjqrux_10175190917092722.js)。该 url 是浏览器在主 url 的初始 GET 后执行的下一个 GET 请求。到目前为止我尝试过的所有方法都无法让我得到那个cookie。

到目前为止的代码

from requests_html import HTMLSession

url=r'https://www.reliant.com'
url2=r'https://www.reliant.com/ruxitagentjs_ICA2QSVfhjqrux_10175190917092722.js'
headers={
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
 'Accept-Encoding': 'gzip, deflate, br',
 'Accept-Language': 'en-US,en;q=0.9',
 'Cache-Control': 'max-age=0',
 'Connection': 'keep-alive',
 'Host': 'www.reliant.com',
 'Sec-Fetch-Mode': 'navigate',
 'Sec-Fetch-Site': 'none',
 'Sec-Fetch-User': '?1',
 'Upgrade-Insecure-Requests': '1',
 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.3'
}

headers2={
'Referer': 'https://www.reliant.com',
 'Sec-Fetch-Mode': 'no-cors',
 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; …
Run Code Online (Sandbox Code Playgroud)

javascript python authentication python-requests python-requests-html

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

Pyodbc:如何将元组作为查询参数传递?

快速概述:

这里的想法是从 csv 文件中读取一些数据,并将其用作我的 sql 查询部分中的列表NOT IN。我使用下面的代码连接到数据库(.mdb)。注意LP是我试图传递的元组/列表,IRdb是数据库的路径

constr = r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=' + IRdb
conn = pyodbc.connect(constr, autocommit=True)
cur = conn.cursor()

IRsql='''SELECT IRRPResults.RRPName, IRRPResults.PointName, IRRPResults.RiskPerTime FROM IRRPResults 
WHERE IRRPResults.PointName<>? 
AND IRRPResults.RRPName NOT LIKE ? AND IRRPResults.PointName NOT IN ?'''

cur.execute(IRsql,('Total',r'Conn%',LP))
Run Code Online (Sandbox Code Playgroud)

问题:

除了执行语句(在我添加该NOT IN部分之前它确实有效)之外,一切都工作正常。我尝试过LP作为字符串、元组和列表传递,但似乎没有任何效果。我收到以下错误

pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Microsoft Access Driver] In operator without () in query expression 'IRRPResults.PointName<>Pa_RaM000 AND IRRPResults.RRPName NOT LIKE Pa_RaM001 AND IRRPResults.PointName NOT IN Pa_RaM002'. …
Run Code Online (Sandbox Code Playgroud)

python sql ms-access pyodbc

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

Reverse String but keep character pairs together

I have analysed the global header of a PCAP file and found out that the magic number is: d4 c3 b2 a1

This means that it uses a little endian and all the bytes that come after it need to processed in reverse order. The other sections of the global header are as follows:

major version =  02 00

minor version =  04 00

time zone =  00 00 00 00

timestamp =  00 00 00 00

snaplen =  ff …
Run Code Online (Sandbox Code Playgroud)

python string reverse python-3.x

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