小编P.h*_*ter的帖子

如何从python 3.5升级到3.6

我的机器在Windows上运行,我试图了解它,但人们只谈论mac和brew其他讨论.我想问一下我是否需要编写一个可以升级核心的命令行,或者我必须从官方网站下载3.6软件包然后卸载3.5然后安装3.6(我不想这样做因为这对我来说听起来很糟糕)

我有 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]

任何帮助?

python python-3.5 python-3.6

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

安装Scrapy错误时出错:需要Microsoft Visual C++ 14.0

我发现scrapy是一个很好的工具刮,所以我试图在我的机器上安装scrapy,但是当我试着pip install scrapy安装一段时间并把它扔给我这个错误..

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
Run Code Online (Sandbox Code Playgroud)

我试图在虚拟环境中安装它,但问题仍然存在.

编辑:这是我错误后得到的..

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "d:\pycharmprojects\environments\scrapyenv\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\User\\AppData\\Local\\Temp\\pip-build-arbeqlly\\Twisted\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\User\AppData\Local\Temp\pip-jdj93131-record\install-record.txt --single-version-externally-managed --compile --install-headers d:\pycharmprojects\environments\scrapyenv\include\site\python3.5\Twisted" failed with error code 1 in C:\Users\User\AppData\Local\Temp\pip-build-arbeqlly\Twisted\
Run Code Online (Sandbox Code Playgroud)

任何帮助?

python scrapy

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

TypeError:'Response'类型的对象没有len()[BeautifulSoup]

我正在尝试登录我的大学网站,然后从中删除数据,(暂时只是欢迎页面的源代码),但我现在得到这个跟踪追溯..

Traceback (most recent call last):
   File "C:/Users/HUNTER/PycharmProjects/Encryption/erp.py", line 16, in   <module>
   soup = BeautifulSoup(opens, 'lxml')
   File "C:\Users\HUNTER\AppData\Local\Programs\Python\Python35-32\lib\site-packages\bs4\__init__.py", line 192, in __init__
   elif len(markup) <= 256 and (
   TypeError: object of type 'Response' has no len()  
Run Code Online (Sandbox Code Playgroud)

这是代码..

 import requests
 from requests import session
 from bs4 import BeautifulSoup

 url = 'http://erp.college_name.edu/'

 r = requests.session()
 data = {

    'tbUserName': 'username',
    'tbPassword': 'password'

 } 

opens = r.post(url=url, data=data)
soup = BeautifulSoup(opens, 'lxml')
print(soup)
Run Code Online (Sandbox Code Playgroud)

帮助真的很适合..

UPDATE

那样做,
soup = BeautifulSoup(opens.text, 'lxml')
print(soup)

给了我这个..

  C:\Users\HUNTER\AppData\Local\Programs\Python\Python35-32\python.exe …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping python-3.x python-requests

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

谷歌sign_in:如何在javascript api中使用redirect_uri

我正在尝试将谷歌登录集成到我的网站中,并且我使用firebase进行身份验证,然后我授权用户访问他们的谷歌驱动器。

在访问他们之后,Google drives我希望页面重定向到另一个页面。(localhost:8080/afterlogin),其中将显示“ WELCOME

但是用户没有到达所需的页面,我已在开发人员控制台中添加了确切的 redierct_uri 但没有帮助。

这是我用于初始化 auth 对象的代码。

gapi.load('auth2', function () {
        // Retrieve the singleton for the GoogleAuth library and set up the client.
        auth2 = gapi.auth2.init({
            client_id: 'MYID.apps.googleusercontent.com',
            cookiepolicy: 'single_host_origin',
            redirect_uri: 'http://localhost:8080/afterlogin'

            // Request scopes in addition to 'profile' and 'email'
            //scope: 'additional_scope'
        });
Run Code Online (Sandbox Code Playgroud)

我正在使用 javascript,并且我在文档中读到 javascript api 不使用redirect_uris

但是在这里的文档中

据说我们可以通过使用gapi.auth2.ClientConfig而不是添加redirect_uris gapi.auth2.init

但是,使用gapi.auth2.ClientConfig而不是gapi.auth2.init给我带来错误。所以我添加了redirect_uri后一个,如上面的代码所示。也许这就是它不起作用的原因?

或者我在使用时做错了什么gapi.auth2.ClientConfig

有什么猜测吗?

javascript redirect google-api firebase-authentication google-signin

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

python 循环提取 API 数据以迭代 URL

I'm trying to set up a for loop to pull in elected representatives' data for about 600,000 postal codes. 基本 URL 保持不变,唯一改变的部分是邮政编码。

理想情况下,我想创建所有邮政编码的列表,然后使用 requests.get 提取列表中所有邮政编码的数据。我在下面想出了这个代码,但它只是为我的列表中的最后一个邮政编码提取数据。我不确定为什么会发生这种情况,我是一名 Python 初学者 - 所以任何帮助将不胜感激!


#loop test 
postcodes = ['P0L1B0','P5A3P1', 'P5A3P2', 'P5A3P3']

for i in range(len(postcodes)):
   rr = requests.get('https://represent.opennorth.ca/postcodes/{}'.format(postcodes[i]))

data1=json.loads(rr.text)

data1
Run Code Online (Sandbox Code Playgroud)

python api iteration loops

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

迭代字典列表时避免KeyError

我有一个词典列表:

test = [{'first': '1'}, {'second': '2'}, {'first': '0'}, {'third': '3'}, {'fourth': '4'}]
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时:

stuff = [L['first'] for L in test]
print(stuff)
Run Code Online (Sandbox Code Playgroud)

我明白了:

Traceback (most recent call last):
  File "C:/Users/User/Desktop/test_run.py", line 4, in <module>
    stuff = [L['first'] for L in test]
  File "C:/Users/User/Desktop/test_run.py", line 4, in <listcomp>
    stuff = [L['first'] for L in test]
KeyError: 'first'
Run Code Online (Sandbox Code Playgroud)

我知道我可能会犯一个愚蠢的错误,但任何帮助?

python dictionary list-comprehension

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

flask:在路由中散列“#”

我最近正在使用 google API,并使用简单的 Flask 方法来检索一些 id_token。

这是我的代码,注释中有解释:

@app.route('/afterlogin/id_token')
def afterlogin(id):  # get the id
    print(id)  # print it 
    return render_template(r'creds_view.html', data=id) # and render the template with 'id' in it (for test purposes)
Run Code Online (Sandbox Code Playgroud)

那么发生的情况是,用户登录后,API 将重定向id_tokenhttp://localhost:8000/afterlogin/#id_token=some_id_token.

但由于某种原因,它向我显示 404 错误。我认为这是因为网址中的“#”,我想要id_token. 我知道html中的“#”意味着“href”中的路径链接或路由。

所以我尝试过。

@app.route('/afterlogin/<path:id>')
Run Code Online (Sandbox Code Playgroud)

但错误仍然存​​在。

有什么猜测吗?

python url routes url-routing flask

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