You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Function load_pin returns following error: in py3pin\Pinterest.py", line 718, in load_pin pinJsonData = json.loads(s.contents[0])["response"]["data"]["v3GetPinQuery"]["data"] KeyError: 'v3GetPinQuery'
The text was updated successfully, but these errors were encountered:
Function load_pin returns following error: in py3pin\Pinterest.py", line 718, in load_pin pinJsonData = json.loads(s.contents[0])["response"]["data"]["v3GetPinQuery"]["data"]KeyError: 'v3GetPinQuery'
Adjust the load_pin method
def load_pin(self, pin_id):
"""
Loads full information about a pin
:param pin_id: pin id to load
:return: python dict describing the pinterest response
:raises: Exception if pin data cannot be found or parsed
"""
try:
resp = self.get(url=self.LOAD_PIN_URL_FORMAT.format(pin_id))
resp.raise_for_status() # Raises an HTTPError for bad responses
except Exception as e:
raise Exception(f"Failed to fetch pin data: {str(e)}")
try:
soup = BeautifulSoup(resp.text, "html.parser")
script = soup.find("script", id="__PWS_INITIAL_PROPS__")
if not script:
raise Exception("__PWS_INITIAL_PROPS__ script not found. Pinterest may have changed their structure.")
data = json.loads(script.string)
pin_data = data["initialReduxState"]["pins"].get(pin_id)
if not pin_data:
raise Exception(f"Pin data not found for pin_id: {pin_id}")
return pin_data
except json.JSONDecodeError:
raise Exception("Failed to parse JSON data from __PWS_INITIAL_PROPS__")
except KeyError as e:
raise Exception(f"Expected key not found in Pinterest response: {str(e)}")
except Exception as e:
raise Exception(f"An unexpected error occurred: {str(e)}")
Function load_pin returns following error: in py3pin\Pinterest.py", line 718, in load_pin
pinJsonData = json.loads(s.contents[0])["response"]["data"]["v3GetPinQuery"]["data"]
KeyError: 'v3GetPinQuery'
The text was updated successfully, but these errors were encountered: