Python to Iron Python

Hey, Im not an expert in python, so i am facing problems in running the following code in dynamo “Python” node.
I think im writing the code in pyhton syntax, and there is some difference in dynamo ironpython, right?
And there are some alternative libraries as well!

can u please help me run this in dynamo to get the results in the end! Shall be very grateful

import requests

from bs4 import BeautifulSoup

from requests.api import get

url1= "https://www.olx.com.pk/"

search="steel"

hiphonadded = '-'.join(search.split())

url2= url1+"items/q-"+hiphonadded

r= requests.get(url2)

HTMLcontent= r.content

soup=BeautifulSoup(HTMLcontent, 'html.parser')

for div in soup.findAll('div', attrs={'class':'_1166cb4b'}):

    links=div.find('a')['href']

    plink="https://www.olx.com.pk"+links

    r2= requests.get(plink)

    page_html= r2.content

    page_soup = BeautifulSoup(page_html, 'html.parser')

    price_class = page_soup.findAll("div", {"class":"f9ddd0c8 _9db31426 f432d8bd"})

    if (len(price_class) > 0):

        price = price_class[0].span.text

        loc_class = page_soup.findAll("div", {"class":"f9ddd0c8 e3cecb8b f432d8bd"})

        location = loc_class[0].span.text

        pname_class = page_soup.findAll("h1", {"class":"a38b8112"})

        pname=pname_class[0].text

        seller_class = page_soup.findAll("div", {"class":"f9ddd0c8 _6caa7349 _1aaedb71 _04adbf51"})

        seller = seller_class[0].span.text

        #print output

        print(pname)

        print(plink)

        print(seller)

        print(location)

        print(price)

Hello
your code works fine on IronPython

make sure you have the version 2.18.4 of the requests package

1 Like

wow @c.poupin, you belong to next level generation bro! :heart_eyes:

Well I’ve installed those libraries, same versions as you said:

Its working fine till:
image

But as soon as i write my script, it shows these warnings. Please help

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 16, in
File “C:\Program Files\IronPython 2.7\Lib\site-packages\requests\api.py”, line 72, in get
File “C:\Program Files\IronPython 2.7\Lib\site-packages\requests\api.py”, line 58, in request
File “C:\Program Files\IronPython 2.7\Lib\site-packages\requests\sessions.py”, line 618, in send
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\socket.py”, line 228, in meth
File “C:\Program Files\IronPython 2.7\Lib\site-packages\requests\sessions.py”, line 508, in request
File “C:\Program Files\IronPython 2.7\Lib\site-packages\requests\adapters.py”, line 430, in send
File “C:\Program Files\IronPython 2.7\Lib\site-packages\urllib3\connectionpool.py”, line 598, in urlopen
File “C:\Program Files\IronPython 2.7\Lib\site-packages\urllib3\connectionpool.py”, line 346, in _make_request
File “C:\Program Files\IronPython 2.7\Lib\site-packages\urllib3\connectionpool.py”, line 850, in validate_conn
File “C:\Program Files\IronPython 2.7\Lib\site-packages\urllib3\connection.py”, line 319, in connect
File "C:\Program Files\IronPython 2.7\Lib\site-packages\urllib3\util\ssl
.py", line 341, in ssl_wrap_socket
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\ssl.py”, line 359, in wrap_socket
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\ssl.py”, line 611, in init
File “C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8\ssl.py”, line 842, in do_handshake
SystemError: Cannot access a disposed object.
Object name: ‘System.Net.Sockets.Socket’.

Could you try using the 2.7.11 version? Also, the message about the PATH Reference to 2.7/scripts?

1 Like

@SeanP yes that is what I am using, i downloaded the lastest IronPython 2.7.11 version .msi from Release IronPython 2.7.11 · IronLanguages/ironpython2 · GitHub and installed it.

If you have link for a better version, please share

@SeanP
image

The latest stable version of IronPython is [IronPython 2.7.11], which is compatible with [Python 2.7]

you think i should get python 2.7? Ive 3.7.9

with Revit 2020 the Python nodes are running on IronPython 2.7.8 and when we try to install the ‘BeautifulSoup’ package on this version (Ipy 2.7.8) we get this warning


if possible, try with Revit 2021 (Python nodes run on IronPython 2.7.9) or try to use Net framework

3 Likes

you are right dear, I’ve tried it on my friends system (Revit2021), its working fine there. @fil

1 Like

Thankyou so muchhhh guys, it was a great help! :smiling_face_with_three_hearts: