0

I am trying to make a program that requests to steam to get a the cheapest price for an item. For this I will be using StatTrak™ P250 | Supernova (Factory New) as an example.

The problem is that when requesting, you will make a url:

http://www.steamcommunity.com/market/priceoverview/?country=SG&currency=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29

Afterwards, (I am using the requests module) I do this:

url = "http://www.steamcommunity.com/market/priceoverview/?country=SG&currency=13&appid=730&market_hash_name=StatTrak™%20P250%20%7C%20Supernova%20%28Factory%20New%29"
requests.get(url)

However, the server will return an error.

I can't seem to find solutions to replace ™. I have tried %2122. In python I tried using u'\u084a' but that didn't work too. The problem is that python sends literally \u084a in the request. Is there any way to solve this?

Moon Cheesez
  • 2,489
  • 3
  • 24
  • 38

1 Answers1

2

Just use URL encoding. You can't use unicode in urls.

>>> import urllib 
>>> f = {'market_hash_name': 'StatTrak™'}
>>> urllib.urlencode(f)
'market_hash_name=StatTrak%E2%84%A2'

Also possible

>>> urllib.quote_plus('StatTrak™')
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49