【发布时间】:2022-01-09 07:26:37
【问题描述】:
关于我的代码收到的 TypeError 的问题。
代码的开始:
domain = "https://bdgastore.com"
handle = 'xt-4-advanced-8'
url = domain + "/products/" + handle + ".json"
##
# Product information
##
shoeSize = "11"
quantity = "1"
options = webdriver.ChromeOptions()
options.add_argument("--incognito")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--headless") # Comment that line to see script running in Chrome.
driver = webdriver.Chrome(ChromeDriverManager().install())
response = urllib.request.urlopen(url)
data = response.read()
#information
first_name='Name';
family_name='Last Name';
email='youremail@gmail.com';
address='12345 Some Street';
country='AU';
city='Mermaid Beach';
postcode='4218';
state='QLD';
mobile='0421667754';
CCNumber="1"
CCName="Test"
CCExpiry="11/25"
CCVerification="123"
#Checkout process
checkoutDetails = 'checkout[shipping_address][first_name]='+ first_name +'&checkout[shipping_address][last_name]='+ family_name +'&checkout[email]='+ email +'&checkout[shipping_address][address1]='+ address +'&checkout[shipping_address][city]='+ city +'&checkout[shipping_address][zip]='+ postcode +'&checkout[shipping_address][country_code]='+ country +'&&checkout[shipping_address][province_code]='+ state +'&checkout[shipping_address][phone]='+ mobile;
代码如下:
for variants in data['product']['variants']:
if ((variants['inventory_quantity'] > 0) and (variants['title'] == shoeSize)):
link = domain + '/cart/'+ str(variants['id']) +':'+ quantity +'?'+ checkoutDetails;
driver.get(link)
而我收到的错误是
TypeError: byte indices must be integers or slices, not str
提前非常感谢您,抱歉,我还是新手。
【问题讨论】:
-
不要用
str索引bytes对象。 -
能否提供
data或variants的数据,一点点。 -
data最有可能是byte类型。