Question

What's wrong with this Python code?

  • 27 March 2024
  • 1 reply
  • 25 views

I’m trying to use Code by Zapier to extract some hexadecimal characters from an input URL, concatenate them with hyphens, then generate an output URL. Using Zapier’s AI code-gen tool, I got this:

import re

# Extract the original URL from the input data
original_url = input_data["original_url"]

# Define a regular expression pattern to match the hexadecimal characters in the original URL
pattern = r"name_([^/_]+?)_([^/_]+?)_([^/_]+?)_([^/_]+?)_([^/_]+?)/master\.m3u8"

# Extract the hexadecimal characters from the original URL using the defined pattern
match = re.match(pattern, original_url)

# Join the extracted hexadecimal characters with hyphens
uuid_like = "-".join(match.groups())

# Define the base URL for the output
base_url = "https://vod.chdrstatic.com/transcode/"

# Concatenate the base URL, the extracted and joined hexadecimal characters, and the file extension to form the final output URL
output_url = f"{base_url}{uuid_like}/{uuid_like}.mp4"

# Store the final output URL in a dictionary with the key as "output"
output = {"output": output_url}

To my non-coder eyes, this looks about right, but whenever I test it, I get the following error:

Traceback (most recent call last): File "<string>", line 20, in the_function AttributeError: 'NoneType' object has no attribute 'groups'

 

Any ideas what’s up or what I need to fix?


1 reply

Userlevel 7
Badge +14

Hi @Matt Gross 

Help articles for using Code in Zaps: https://zapier.com/apps/code/help

 

You may want to try asking ChatGPT for help fixing/optimizing the code.

Reply