小编Des*_*sAu的帖子

切片索引必须是整数或无或具有__index__方法

我正在尝试使用Python.我想在几个列表(L [i])中切片列表(高原),但我有以下错误消息:

  File "C:\Users\adescamp\Skycraper\skycraper.py", line 20, in <module>
    item = plateau[debut:fin]
TypeError: slice indices must be integers or None or have an __index__ method
Run Code Online (Sandbox Code Playgroud)

有关线是与之相关的 item = plateau[debut:fin]

from math import sqrt

plateau = [2, 3, 1, 4, 1, 4, 2, 3, 4, 1, 3, 2, 3, 2, 4, 1]

taille = sqrt(len(plateau))

# Division en lignes
L = []
i = 1
while i < taille:
    fin = i * taille
    debut = fin - taille
    item = plateau[debut:fin] …
Run Code Online (Sandbox Code Playgroud)

python slice

50
推荐指数
1
解决办法
15万
查看次数

接受对 S3 的 CORS 请求以进行文件显示,但不接受 Javascript 库的加载

我正在开发一个小型 javascript 浏览器脚本,用于从 S3 检索文件。

向 S3 请求 SignedUrl 后,我可以在标签中显示图像,没有任何问题。为此,我更新了 S3 上的 CORS 策略:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "HEAD",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": []
    }
]
Run Code Online (Sandbox Code Playgroud)

但是,当我想使用相同的 URL 提取 EXIF 数据(使用ExifReader)时,我收到有关 CORS 策略的错误消息:

Access to fetch at '*SIGNEDURL*' from origin 'null' has been blocked
by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 
If an opaque response serves your needs, set the request's mode to …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3

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

Python:在字符串上查找返回无

我正在研究一个解析 HTML 页面的项目。它适用于公司内部的网站,但我更改了示例,以便您可以尝试。

我得到一个 HTML 页面的源代码并搜索某个标记。然后我想提取这个标记的一个子字符串,但它不起作用。Python 返回一个 none... Hier 在我的代码下面,在注释中是 Python 的返回:

#!/usr/bin/python
import urllib2
from bs4 import BeautifulSoup

response = urllib2.urlopen("http://www.resto.be/restaurant/liege/4000-liege/8219-le-bar-a-gouts/")
page_source = response.read()

soup = BeautifulSoup(page_source)
name = soup.find_all("meta", attrs={"itemprop":"name"})
print(name[0])
# <meta content="LE BAR A GOUTS" itemprop="name"/>

print(name[0].find("<meta"))
# none
Run Code Online (Sandbox Code Playgroud)

python urllib2 beautifulsoup

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

标签 统计

python ×2

amazon-s3 ×1

beautifulsoup ×1

javascript ×1

slice ×1

urllib2 ×1