I make script for shopify cart since it is impossible to purchase manually, when I ran the script to my command prompt,
it says ,
line 109, in AttributeError: "str’ object has no attribute
‘text
Scrape Product Info based on selected colors
if blue and cinder:
productInfo(urlBlueResponse.text)
productInfo(urlCinderResponse.text)
elif blue:
productInfo(urlBlueResponse.text)
elif cinder:
productInfo(urlCinderResponse.text)
else:
print(Fore.RED + timestamp
I was told it was from a capitalization mismatch, can somebody please explain this to me. I am new to coding and I want to learn all I can.
3
Answers
This error happened when you tried to access an attribute on a string object —
.text
— that does not exist as an element on that object.It looks like your code is working with HTTP request and response objects of some kind:
urlBlueResponse
It is plausible that you got an error or some other unexpected behavior in the request/response cycle that resulted in one of the response objects returning a
str
(string) type instead of a response object with a text attribute. I suggest you handle the exception with a try/except block:*Link: (Re-raise exception with a different type and message, preserving existing information)
Based on the error message, either
urlBlueResponse
orurlCinderResponse
(or both) are a string datatype. The way you are using them, it appears you expect these to be objects which have atext
attribute. The error message is telling you that they’restr
objects and don’t havetext
attributes.